28
28
import org .junit .Test ;
29
29
30
30
import java .util .concurrent .CountDownLatch ;
31
- import java .util .concurrent .TimeUnit ;
32
31
33
32
import static org .junit .Assert .assertEquals ;
34
33
import static org .junit .Assert .assertFalse ;
@@ -46,9 +45,9 @@ public class OfflineClientTest extends OfflineTestBase {
46
45
public void testListIndexes () throws Exception {
47
46
final CountDownLatch signal = new CountDownLatch (1 );
48
47
final OfflineIndex index = client .getOfflineIndex (Helpers .getMethodName ());
49
- client .listIndexesOfflineAsync (new CompletionHandler () {
48
+ client .listIndexesOfflineAsync (new AssertCompletionHandler () {
50
49
@ Override
51
- public void requestCompleted (JSONObject content , AlgoliaException error ) {
50
+ public void doRequestCompleted (JSONObject content , AlgoliaException error ) {
52
51
// Check that response is valid.
53
52
assertNotNull (content );
54
53
JSONArray items = content .optJSONArray ("items" );
@@ -62,17 +61,17 @@ public void requestCompleted(JSONObject content, AlgoliaException error) {
62
61
assertNotEquals (index .getName (), name );
63
62
}
64
63
final OfflineIndex .WriteTransaction transaction = index .newTransaction ();
65
- transaction .saveObjectAsync (objects .get ("snoopy" ), new CompletionHandler () {
64
+ transaction .saveObjectAsync (objects .get ("snoopy" ), new AssertCompletionHandler () {
66
65
@ Override
67
- public void requestCompleted (JSONObject content , AlgoliaException error ) {
66
+ public void doRequestCompleted (JSONObject content , AlgoliaException error ) {
68
67
assertNull (error );
69
- transaction .commitAsync (new CompletionHandler () {
68
+ transaction .commitAsync (new AssertCompletionHandler () {
70
69
@ Override
71
- public void requestCompleted (JSONObject content , AlgoliaException error ) {
70
+ public void doRequestCompleted (JSONObject content , AlgoliaException error ) {
72
71
assertNull (error );
73
- client .listIndexesOfflineAsync (new CompletionHandler () {
72
+ client .listIndexesOfflineAsync (new AssertCompletionHandler () {
74
73
@ Override
75
- public void requestCompleted (JSONObject content , AlgoliaException error ) {
74
+ public void doRequestCompleted (JSONObject content , AlgoliaException error ) {
76
75
// Check that response is valid.
77
76
assertNotNull (content );
78
77
JSONArray items = content .optJSONArray ("items" );
@@ -98,26 +97,25 @@ public void requestCompleted(JSONObject content, AlgoliaException error) {
98
97
});
99
98
}
100
99
});
101
- assertTrue ("No callback was called" , signal .await (waitTimeout , TimeUnit .SECONDS ));
102
100
}
103
101
104
102
@ Test
105
103
public void testDeleteIndex () throws Exception {
106
104
final CountDownLatch signal = new CountDownLatch (1 );
107
105
final OfflineIndex index = client .getOfflineIndex (Helpers .getMethodName ());
108
106
final OfflineIndex .WriteTransaction transaction = index .newTransaction ();
109
- transaction .saveObjectsAsync (new JSONArray (objects .values ()), new CompletionHandler () {
107
+ transaction .saveObjectsAsync (new JSONArray (objects .values ()), new AssertCompletionHandler () {
110
108
@ Override
111
- public void requestCompleted (JSONObject content , AlgoliaException error ) {
109
+ public void doRequestCompleted (JSONObject content , AlgoliaException error ) {
112
110
assertNull (error );
113
- transaction .commitAsync (new CompletionHandler () {
111
+ transaction .commitAsync (new AssertCompletionHandler () {
114
112
@ Override
115
- public void requestCompleted (JSONObject content , AlgoliaException error ) {
113
+ public void doRequestCompleted (JSONObject content , AlgoliaException error ) {
116
114
assertNull (error );
117
115
assertTrue (client .hasOfflineData (index .getName ()));
118
- client .deleteIndexOfflineAsync (index .getName (), new CompletionHandler () {
116
+ client .deleteIndexOfflineAsync (index .getName (), new AssertCompletionHandler () {
119
117
@ Override
120
- public void requestCompleted (JSONObject content , AlgoliaException error ) {
118
+ public void doRequestCompleted (JSONObject content , AlgoliaException error ) {
121
119
assertNotNull (content );
122
120
assertNotNull (content .optString ("deletedAt" , null ));
123
121
assertFalse (client .hasOfflineData (index .getName ()));
@@ -128,7 +126,6 @@ public void requestCompleted(JSONObject content, AlgoliaException error) {
128
126
});
129
127
}
130
128
});
131
- assertTrue ("No callback was called" , signal .await (waitTimeout , TimeUnit .SECONDS ));
132
129
}
133
130
134
131
@ Test
@@ -137,26 +134,26 @@ public void testMoveIndex() throws Exception {
137
134
final OfflineIndex srcIndex = client .getOfflineIndex (Helpers .getMethodName ());
138
135
final OfflineIndex dstIndex = client .getOfflineIndex (Helpers .getMethodName () + "_new" );
139
136
final OfflineIndex .WriteTransaction transaction = srcIndex .newTransaction ();
140
- transaction .saveObjectsAsync (new JSONArray (objects .values ()), new CompletionHandler () {
137
+ transaction .saveObjectsAsync (new JSONArray (objects .values ()), new AssertCompletionHandler () {
141
138
@ Override
142
- public void requestCompleted (JSONObject content , AlgoliaException error ) {
139
+ public void doRequestCompleted (JSONObject content , AlgoliaException error ) {
143
140
assertNull (error );
144
- transaction .commitAsync (new CompletionHandler () {
141
+ transaction .commitAsync (new AssertCompletionHandler () {
145
142
@ Override
146
- public void requestCompleted (JSONObject content , AlgoliaException error ) {
143
+ public void doRequestCompleted (JSONObject content , AlgoliaException error ) {
147
144
assertNull (error );
148
145
assertTrue (client .hasOfflineData (srcIndex .getName ()));
149
146
assertFalse (client .hasOfflineData (dstIndex .getName ()));
150
- client .moveIndexOfflineAsync (srcIndex .getName (), dstIndex .getName (), new CompletionHandler () {
147
+ client .moveIndexOfflineAsync (srcIndex .getName (), dstIndex .getName (), new AssertCompletionHandler () {
151
148
@ Override
152
- public void requestCompleted (JSONObject content , AlgoliaException error ) {
149
+ public void doRequestCompleted (JSONObject content , AlgoliaException error ) {
153
150
assertNotNull (content );
154
151
assertNotNull (content .optString ("updatedAt" , null ));
155
152
assertFalse (client .hasOfflineData (srcIndex .getName ()));
156
153
assertTrue (client .hasOfflineData (dstIndex .getName ()));
157
- dstIndex .searchAsync (new Query ("woodstock" ), new CompletionHandler () {
154
+ dstIndex .searchAsync (new Query ("woodstock" ), new AssertCompletionHandler () {
158
155
@ Override
159
- public void requestCompleted (JSONObject content , AlgoliaException error ) {
156
+ public void doRequestCompleted (JSONObject content , AlgoliaException error ) {
160
157
assertNotNull (content );
161
158
assertEquals (1 , content .optInt ("nbHits" ));
162
159
signal .countDown ();
@@ -168,6 +165,5 @@ public void requestCompleted(JSONObject content, AlgoliaException error) {
168
165
});
169
166
}
170
167
});
171
- assertTrue ("No callback was called" , signal .await (waitTimeout , TimeUnit .SECONDS ));
172
168
}
173
169
}
0 commit comments