Skip to content

Commit 91b1629

Browse files
authored
Merge branch 'main' into mattcreaser/fix-password-auth-device-metadata
2 parents 6f85432 + 320836b commit 91b1629

File tree

18 files changed

+277
-581
lines changed

18 files changed

+277
-581
lines changed

aws-datastore/src/androidTest/java/com/amplifyframework/datastore/DatastoreCanaryTest.kt

Lines changed: 12 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ import com.amplifyframework.testmodels.commentsblog.AmplifyModelProvider
2323
import com.amplifyframework.testmodels.commentsblog.Post
2424
import com.amplifyframework.testmodels.commentsblog.PostStatus
2525
import com.amplifyframework.testutils.HubAccumulator
26+
import com.amplifyframework.testutils.sync.SynchronousDataStore
2627
import java.util.UUID
27-
import java.util.concurrent.CountDownLatch
2828
import java.util.concurrent.TimeUnit
2929
import org.junit.After
30-
import org.junit.Assert.assertTrue
31-
import org.junit.Assert.fail
3230
import org.junit.BeforeClass
3331
import org.junit.Test
3432

@@ -53,45 +51,26 @@ class DatastoreCanaryTest {
5351
}
5452
}
5553

54+
val syncDatastore = SynchronousDataStore.delegatingTo(Amplify.DataStore)
55+
5656
@After
5757
fun teardown() {
58-
val latch = CountDownLatch(1)
59-
Amplify.DataStore.clear(
60-
{ latch.countDown() },
61-
{
62-
latch.countDown()
63-
Log.e(TAG, "Error clearing DataStore", it)
64-
}
65-
)
66-
latch.await(TIMEOUT_S, TimeUnit.SECONDS)
58+
syncDatastore.clear()
6759
}
6860

6961
@Test
7062
fun save() {
71-
val latch = CountDownLatch(1)
7263
val post = Post.builder()
7364
.title("Post" + UUID.randomUUID().toString())
7465
.status(PostStatus.ACTIVE)
7566
.rating(3)
7667
.build()
77-
78-
Amplify.DataStore.save(
79-
post,
80-
{ latch.countDown() },
81-
{ fail("Error creating post: $it") }
82-
)
83-
assertTrue(latch.await(TIMEOUT_S, TimeUnit.SECONDS))
68+
syncDatastore.save(post)
8469
}
8570

8671
@Test
8772
fun query() {
88-
val latch = CountDownLatch(1)
89-
Amplify.DataStore.query(
90-
Post::class.java,
91-
{ latch.countDown() },
92-
{ fail("Error retrieving posts: $it") }
93-
)
94-
assertTrue(latch.await(TIMEOUT_S, TimeUnit.SECONDS))
73+
syncDatastore.query(Post::class.java)
9574
}
9675

9776
@Test
@@ -103,75 +82,33 @@ class DatastoreCanaryTest {
10382
.id(UUID.randomUUID().toString())
10483
.build()
10584

106-
val saveLatch = CountDownLatch(1)
10785
val createHub = HubAccumulator.create(
10886
HubChannel.DATASTORE,
10987
DataStoreHubEventFilters.enqueueOf(Post::class.simpleName, post.id),
11088
1
11189
).start()
11290

113-
Amplify.DataStore.save(
114-
post,
115-
{ saveLatch.countDown() },
116-
{ fail("Error creating post: $it") }
117-
)
118-
saveLatch.await(TIMEOUT_S, TimeUnit.SECONDS)
91+
syncDatastore.save(post)
11992
createHub.await(TIMEOUT_S.toInt(), TimeUnit.SECONDS)
12093

121-
val deleteLatch = CountDownLatch(1)
122-
Amplify.DataStore.delete(
123-
post,
124-
{ deleteLatch.countDown() },
125-
{ fail("Failed to delete post: $it") }
126-
)
94+
syncDatastore.delete(post)
95+
12796
// Temporarily prevent https://github.com/aws-amplify/amplify-android/issues/2617
12897
Thread.sleep(1000)
129-
assertTrue(deleteLatch.await(TIMEOUT_S, TimeUnit.SECONDS))
13098
}
13199

132100
@Test
133101
fun start() {
134-
val latch = CountDownLatch(1)
135-
Amplify.DataStore.start(
136-
{ latch.countDown() },
137-
{ fail("Error starting DataStore: $it") }
138-
)
139-
assertTrue(latch.await(TIMEOUT_S, TimeUnit.SECONDS))
140-
}
141-
142-
@Test
143-
fun observe() {
144-
val latch = CountDownLatch(1)
145-
Amplify.DataStore.observe(
146-
Post::class.java,
147-
{ latch.countDown() },
148-
{
149-
val post = it.item()
150-
Log.i(TAG, "Post: $post")
151-
},
152-
{ fail("Observation failed: $it") },
153-
{ Log.i(TAG, "Observation complete") }
154-
)
155-
assertTrue(latch.await(TIMEOUT_S, TimeUnit.SECONDS))
102+
syncDatastore.start()
156103
}
157104

158105
@Test
159106
fun stop() {
160-
val latch = CountDownLatch(1)
161-
Amplify.DataStore.stop(
162-
{ latch.countDown() },
163-
{ fail("Error stopping DataStore: $it") }
164-
)
165-
assertTrue(latch.await(TIMEOUT_S, TimeUnit.SECONDS))
107+
syncDatastore.stop()
166108
}
167109

168110
@Test
169111
fun clear() {
170-
val latch = CountDownLatch(1)
171-
Amplify.DataStore.clear(
172-
{ latch.countDown() },
173-
{ fail("Error clearing DataStore: $it") }
174-
)
175-
assertTrue(latch.await(TIMEOUT_S, TimeUnit.SECONDS))
112+
syncDatastore.clear()
176113
}
177114
}

aws-datastore/src/androidTest/java/com/amplifyframework/datastore/DatastoreCanaryTestGen2.kt

Lines changed: 12 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ import com.amplifyframework.testmodels.commentsblog.AmplifyModelProvider
2525
import com.amplifyframework.testmodels.commentsblog.Post
2626
import com.amplifyframework.testmodels.commentsblog.PostStatus
2727
import com.amplifyframework.testutils.HubAccumulator
28+
import com.amplifyframework.testutils.sync.SynchronousDataStore
2829
import java.util.UUID
29-
import java.util.concurrent.CountDownLatch
3030
import java.util.concurrent.TimeUnit
3131
import org.junit.After
32-
import org.junit.Assert.assertTrue
33-
import org.junit.Assert.fail
3432
import org.junit.BeforeClass
3533
import org.junit.Test
3634

@@ -55,45 +53,26 @@ class DatastoreCanaryTestGen2 {
5553
}
5654
}
5755

56+
val syncDatastore = SynchronousDataStore.delegatingTo(Amplify.DataStore)
57+
5858
@After
5959
fun teardown() {
60-
val latch = CountDownLatch(1)
61-
Amplify.DataStore.clear(
62-
{ latch.countDown() },
63-
{
64-
latch.countDown()
65-
Log.e(TAG, "Error clearing DataStore", it)
66-
}
67-
)
68-
latch.await(TIMEOUT_S, TimeUnit.SECONDS)
60+
syncDatastore.clear()
6961
}
7062

7163
@Test
7264
fun save() {
73-
val latch = CountDownLatch(1)
7465
val post = Post.builder()
7566
.title("Post" + UUID.randomUUID().toString())
7667
.status(PostStatus.ACTIVE)
7768
.rating(3)
7869
.build()
79-
80-
Amplify.DataStore.save(
81-
post,
82-
{ latch.countDown() },
83-
{ fail("Error creating post: $it") }
84-
)
85-
assertTrue(latch.await(TIMEOUT_S, TimeUnit.SECONDS))
70+
syncDatastore.save(post)
8671
}
8772

8873
@Test
8974
fun query() {
90-
val latch = CountDownLatch(1)
91-
Amplify.DataStore.query(
92-
Post::class.java,
93-
{ latch.countDown() },
94-
{ fail("Error retrieving posts: $it") }
95-
)
96-
assertTrue(latch.await(TIMEOUT_S, TimeUnit.SECONDS))
75+
syncDatastore.query(Post::class.java)
9776
}
9877

9978
@Test
@@ -105,75 +84,33 @@ class DatastoreCanaryTestGen2 {
10584
.id(UUID.randomUUID().toString())
10685
.build()
10786

108-
val saveLatch = CountDownLatch(1)
10987
val createHub = HubAccumulator.create(
11088
HubChannel.DATASTORE,
11189
DataStoreHubEventFilters.enqueueOf(Post::class.simpleName, post.id),
11290
1
11391
).start()
11492

115-
Amplify.DataStore.save(
116-
post,
117-
{ saveLatch.countDown() },
118-
{ fail("Error creating post: $it") }
119-
)
120-
saveLatch.await(TIMEOUT_S, TimeUnit.SECONDS)
93+
syncDatastore.save(post)
12194
createHub.await(TIMEOUT_S.toInt(), TimeUnit.SECONDS)
12295

123-
val deleteLatch = CountDownLatch(1)
124-
Amplify.DataStore.delete(
125-
post,
126-
{ deleteLatch.countDown() },
127-
{ fail("Failed to delete post: $it") }
128-
)
96+
syncDatastore.delete(post)
97+
12998
// Temporarily prevent https://github.com/aws-amplify/amplify-android/issues/2617
13099
Thread.sleep(1000)
131-
assertTrue(deleteLatch.await(TIMEOUT_S, TimeUnit.SECONDS))
132100
}
133101

134102
@Test
135103
fun start() {
136-
val latch = CountDownLatch(1)
137-
Amplify.DataStore.start(
138-
{ latch.countDown() },
139-
{ fail("Error starting DataStore: $it") }
140-
)
141-
assertTrue(latch.await(TIMEOUT_S, TimeUnit.SECONDS))
142-
}
143-
144-
@Test
145-
fun observe() {
146-
val latch = CountDownLatch(1)
147-
Amplify.DataStore.observe(
148-
Post::class.java,
149-
{ latch.countDown() },
150-
{
151-
val post = it.item()
152-
Log.i(TAG, "Post: $post")
153-
},
154-
{ fail("Observation failed: $it") },
155-
{ Log.i(TAG, "Observation complete") }
156-
)
157-
assertTrue(latch.await(TIMEOUT_S, TimeUnit.SECONDS))
104+
syncDatastore.start()
158105
}
159106

160107
@Test
161108
fun stop() {
162-
val latch = CountDownLatch(1)
163-
Amplify.DataStore.stop(
164-
{ latch.countDown() },
165-
{ fail("Error stopping DataStore: $it") }
166-
)
167-
assertTrue(latch.await(TIMEOUT_S, TimeUnit.SECONDS))
109+
syncDatastore.stop()
168110
}
169111

170112
@Test
171113
fun clear() {
172-
val latch = CountDownLatch(1)
173-
Amplify.DataStore.clear(
174-
{ latch.countDown() },
175-
{ fail("Error clearing DataStore: $it") }
176-
)
177-
assertTrue(latch.await(TIMEOUT_S, TimeUnit.SECONDS))
114+
syncDatastore.clear()
178115
}
179116
}

aws-geo-location/src/androidTest/java/com/amplifyframework/geo/location/GeoCanaryTest.kt

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ import com.amplifyframework.AmplifyException
2121
import com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin
2222
import com.amplifyframework.core.Amplify
2323
import com.amplifyframework.geo.models.Coordinates
24-
import java.util.concurrent.CountDownLatch
25-
import java.util.concurrent.TimeUnit
24+
import com.amplifyframework.testutils.sync.SynchronousAuth
25+
import com.amplifyframework.testutils.sync.SynchronousGeo
2626
import org.junit.After
27-
import org.junit.Assert
28-
import org.junit.Assert.fail
2927
import org.junit.BeforeClass
3028
import org.junit.Test
3129

@@ -47,73 +45,41 @@ class GeoCanaryTest {
4745
}
4846
}
4947

48+
private val syncAuth = SynchronousAuth.delegatingToAmplify()
49+
private val syncGeo = SynchronousGeo.delegatingToAmplify()
50+
5051
@After
5152
fun tearDown() {
5253
signOutFromCognito()
5354
}
5455

5556
@Test
5657
fun searchByText() {
57-
val latch = CountDownLatch(1)
5858
signInWithCognito()
5959
val searchQuery = "Amazon Go"
60-
try {
61-
Amplify.Geo.searchByText(
62-
searchQuery,
63-
{
64-
for (place in it.places) {
65-
Log.i(TAG, place.toString())
66-
}
67-
latch.countDown()
68-
},
69-
{ fail("Failed to search for $searchQuery: $it") }
70-
)
71-
} catch (e: Exception) {
72-
fail(e.toString())
60+
val result = syncGeo.searchByText(searchQuery)
61+
for (place in result.places) {
62+
Log.i(TAG, place.toString())
7363
}
74-
Assert.assertTrue(latch.await(TIMEOUT_S, TimeUnit.SECONDS))
7564
}
7665

7766
@Test
7867
fun searchByCoordinates() {
79-
val latch = CountDownLatch(1)
8068
signInWithCognito()
8169
val position = Coordinates(47.6153, -122.3384)
82-
try {
83-
Amplify.Geo.searchByCoordinates(
84-
position,
85-
{
86-
for (place in it.places) {
87-
Log.i(TAG, place.toString())
88-
}
89-
latch.countDown()
90-
},
91-
{ fail("Failed to reverse geocode $position: $it") }
92-
)
93-
} catch (e: Exception) {
94-
fail(e.toString())
70+
val result = syncGeo.searchByCoordinates(position)
71+
for (place in result.places) {
72+
Log.i(TAG, place.toString())
9573
}
96-
Assert.assertTrue(latch.await(TIMEOUT_S, TimeUnit.SECONDS))
9774
}
9875

9976
private fun signInWithCognito() {
100-
val latch = CountDownLatch(1)
10177
val context = ApplicationProvider.getApplicationContext<Context>()
10278
val (username, password) = Credentials.load(context)
103-
Amplify.Auth.signIn(
104-
username,
105-
password,
106-
{ latch.countDown() },
107-
{ Log.e(TAG, "Failed to sign in", it) }
108-
)
109-
latch.await(TIMEOUT_S, TimeUnit.SECONDS)
79+
syncAuth.signIn(username, password)
11080
}
11181

11282
private fun signOutFromCognito() {
113-
val latch = CountDownLatch(1)
114-
Amplify.Auth.signOut {
115-
latch.countDown()
116-
}
117-
latch.await(TIMEOUT_S, TimeUnit.SECONDS)
83+
syncAuth.signOut()
11884
}
11985
}

0 commit comments

Comments
 (0)