Skip to content
This repository was archived by the owner on Mar 10, 2022. It is now read-only.

Commit 73cd521

Browse files
author
Hideki Itakura
committed
Merge pull request #825 from couchbase/feature/issue_821
Fixed #821 - Needs to check if event.getTransition() is null in Test
2 parents 899d34f + 4ed3835 commit 73cd521

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

src/androidTest/java/com/couchbase/lite/LiteTestCaseWithDB.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,8 @@ public ReplicationIdleObserver(CountDownLatch idleSignal) {
833833

834834
@Override
835835
public void changed(Replication.ChangeEvent event) {
836-
if (event.getTransition().getDestination() == ReplicationState.IDLE) {
836+
if (event.getTransition() != null &&
837+
event.getTransition().getDestination() == ReplicationState.IDLE) {
837838
idleSignal.countDown();
838839
}
839840
}
@@ -848,7 +849,8 @@ public ReplicationFinishedObserver(CountDownLatch doneSignal) {
848849

849850
@Override
850851
public void changed(Replication.ChangeEvent event) {
851-
if (event.getTransition().getDestination() == ReplicationState.STOPPED) {
852+
if (event.getTransition() != null &&
853+
event.getTransition().getDestination() == ReplicationState.STOPPED) {
852854
doneSignal.countDown();
853855
assertEquals(event.getChangeCount(), event.getCompletedChangeCount());
854856
}
@@ -864,7 +866,8 @@ public ReplicationOfflineObserver(CountDownLatch offlineSignal) {
864866

865867
@Override
866868
public void changed(Replication.ChangeEvent event) {
867-
if (event.getTransition().getDestination() == ReplicationState.OFFLINE) {
869+
if (event.getTransition() != null &&
870+
event.getTransition().getDestination() == ReplicationState.OFFLINE) {
868871
offlineSignal.countDown();
869872
}
870873
}
@@ -879,7 +882,8 @@ public ReplicationRunningObserver(CountDownLatch runningSignal) {
879882

880883
@Override
881884
public void changed(Replication.ChangeEvent event) {
882-
if (event.getTransition().getDestination() == ReplicationState.RUNNING) {
885+
if (event.getTransition() != null &&
886+
event.getTransition().getDestination() == ReplicationState.RUNNING) {
883887
runningSignal.countDown();
884888
}
885889
}

src/androidTest/java/com/couchbase/lite/replicator/ReplicationTest.java

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4144,7 +4144,7 @@ public void testReplicationRestartPreservesValues() throws Exception {
41444144
* https://github.com/couchbase/couchbase-lite-java-core/issues/383
41454145
*/
41464146
public void testContinuousPullReplicationGoesIdleTwice() throws Exception {
4147-
Log.e(TAG, "TEST START");
4147+
Log.d(TAG, "TEST START");
41484148

41494149
// create mockwebserver and custom dispatcher
41504150
MockDispatcher dispatcher = new MockDispatcher();
@@ -4197,8 +4197,6 @@ public void testContinuousPullReplicationGoesIdleTwice() throws Exception {
41974197
mockRevsDiff.setSticky(true);
41984198
dispatcher.enqueueResponse(MockHelper.PATH_REGEX_REVS_DIFF, mockRevsDiff);
41994199

4200-
Log.e(TAG, "SERVER START");
4201-
42024200
server.play();
42034201

42044202
// create pull replication
@@ -4209,16 +4207,14 @@ public void testContinuousPullReplicationGoesIdleTwice() throws Exception {
42094207
pullReplication.addChangeListener(new Replication.ChangeListener() {
42104208
@Override
42114209
public void changed(Replication.ChangeEvent event) {
4212-
if (event.getTransition().getDestination() == ReplicationState.IDLE) {
4213-
Log.e(TAG, "Replication is IDLE 1");
4210+
if (event.getTransition() != null &&
4211+
event.getTransition().getDestination() == ReplicationState.IDLE) {
4212+
Log.d(TAG, "Replication is IDLE 1");
42144213
enteredIdleState1.countDown();
4215-
pullReplication.removeChangeListener(this);
42164214
}
42174215
}
42184216
});
42194217

4220-
Log.e(TAG, "REPLICATOR START");
4221-
42224218
// 1. start pull replication
42234219
pullReplication.start();
42244220

@@ -4237,46 +4233,48 @@ public void changed(Replication.ChangeEvent event) {
42374233
pullReplication.addChangeListener(new Replication.ChangeListener() {
42384234
@Override
42394235
public void changed(Replication.ChangeEvent event) {
4240-
if (event.getTransition().getDestination() == ReplicationState.RUNNING) {
4236+
if (event.getTransition() != null &&
4237+
event.getTransition().getDestination() == ReplicationState.RUNNING) {
42414238
if (enteredRunningState.getCount() > 0) {
4242-
Log.e(TAG, "Replication is RUNNING");
4239+
Log.d(TAG, "Replication is RUNNING");
42434240
enteredRunningState.countDown();
42444241
}
42454242
}
42464243
// second IDLE change listener
42474244
// handling IDLE event here. It seems IDLE event was fired before set IDLE event handler
4248-
else if (event.getTransition().getDestination() == ReplicationState.IDLE) {
4245+
else if (event.getTransition() != null &&
4246+
event.getTransition().getDestination() == ReplicationState.IDLE) {
42494247
if (enteredRunningState.getCount() <= 0 && enteredIdleState2.getCount() > 0) {
4250-
Log.e(TAG, "Replication is IDLE 2");
4248+
Log.d(TAG, "Replication is IDLE 2");
42514249
enteredIdleState2.countDown();
42524250
}
42534251
}
42544252
}
42554253
});
42564254

42574255
// 4. wait until its RUNNING
4258-
Log.e(TAG, "WAIT for RUNNING");
4256+
Log.d(TAG, "WAIT for RUNNING");
42594257
success = enteredRunningState.await(30, TimeUnit.SECONDS);
42604258
assertTrue(success);
42614259

42624260
// 5. wait until its IDLE again. before the fix, it would never go IDLE again, and so
42634261
// this would timeout and the test would fail.
4264-
Log.e(TAG, "WAIT for IDLE");
4262+
Log.d(TAG, "WAIT for IDLE");
42654263
success = enteredIdleState2.await(30, TimeUnit.SECONDS);
42664264
assertTrue(success);
42674265

4268-
Log.e(TAG, "STOP REPLICATOR");
4266+
Log.d(TAG, "STOP REPLICATOR");
42694267

42704268
// clean up
42714269
stopReplication(pullReplication);
42724270

4273-
Log.e(TAG, "STOP MOCK SERVER");
4271+
Log.d(TAG, "STOP MOCK SERVER");
42744272
} finally {
42754273
server.shutdown();
42764274
}
42774275

42784276

4279-
Log.e(TAG, "TEST DONE");
4277+
Log.d(TAG, "TEST DONE");
42804278
}
42814279

42824280
/**
@@ -4317,7 +4315,7 @@ public void changed(Replication.ChangeEvent event) {
43174315
enteredIdleState.countDown();
43184316
} else if (event.getTransition().getDestination() == ReplicationState.STOPPED) {
43194317
event.getTransition().getDestination();
4320-
Log.e(TAG, "Replication is STOPPED", new Exception("HELLO WORLD"));
4318+
Log.d(TAG, "Replication is STOPPED");
43214319
enteredStoppedState.countDown();
43224320
}
43234321
}
@@ -4450,7 +4448,8 @@ public void testPullReplicatonSendIdleStateAfterCheckPoint() throws Exception {
44504448
pullReplication.addChangeListener(new Replication.ChangeListener() {
44514449
@Override
44524450
public void changed(Replication.ChangeEvent event) {
4453-
if (event.getTransition().getDestination() == ReplicationState.IDLE) {
4451+
if (event.getTransition() != null &&
4452+
event.getTransition().getDestination() == ReplicationState.IDLE) {
44544453
pullInitialIdleState.countDown();
44554454
}
44564455
}
@@ -4475,13 +4474,15 @@ public void changed(Replication.ChangeEvent event) {
44754474
@Override
44764475
public void changed(Replication.ChangeEvent event) {
44774476
Log.e(TAG, "[changed] PULL -> " + event);
4478-
if (event.getTransition().getDestination() == ReplicationState.IDLE) {
4477+
if (event.getTransition() != null &&
4478+
event.getTransition().getDestination() == ReplicationState.IDLE) {
44794479
// make sure pull replicator becomes IDLE after ACTIVE state.
44804480
// so ignore any IDLE state before ACTIVE.
44814481
if (runningSignal.getCount() == 0) {
44824482
idleSignal.countDown();
44834483
}
4484-
} else if (event.getTransition().getDestination() == ReplicationState.RUNNING) {
4484+
} else if (event.getTransition() != null &&
4485+
event.getTransition().getDestination() == ReplicationState.RUNNING) {
44854486
runningSignal.countDown();
44864487
}
44874488
}
@@ -4554,9 +4555,6 @@ public void testPullReplicatonWithManyAttachmentRevisions() throws Exception {
45544555
SavedRevision saved = newRev.save(true);
45554556
String rev2ID = doc.getCurrentRevisionId();
45564557

4557-
Log.w(TAG, "saved => " + saved);
4558-
Log.w(TAG, "revID => " + doc.getCurrentRevisionId());
4559-
45604558
// Create 5 revisions with 50 conflicts each
45614559
int j = 3;
45624560
for (; j < 5; j++) {
@@ -4567,7 +4565,6 @@ public void testPullReplicatonWithManyAttachmentRevisions() throws Exception {
45674565
props.put(key, value);
45684566
RevisionInternal leaf = new RevisionInternal(props);
45694567
database.forceInsert(leaf, new ArrayList<String>(), null);
4570-
Log.w(TAG, "revID => " + doc.getCurrentRevisionId());
45714568

45724569
for (int i = 0; i < 49; i++) {
45734570
// Create a conflict, won by the new revision:
@@ -4595,7 +4592,6 @@ public void testPullReplicatonWithManyAttachmentRevisions() throws Exception {
45954592
revHistory.add(rev2ID);
45964593
revHistory.add(rev1ID);
45974594
database.forceInsert(leaf_conflict, revHistory, null);
4598-
Log.w(TAG, "revID => " + doc.getCurrentRevisionId());
45994595
}
46004596
}
46014597

@@ -4634,7 +4630,8 @@ public void changed(Replication.ChangeEvent event) {
46344630
if (event.getError() != null) {
46354631
Assert.fail("Should not have any error....");
46364632
}
4637-
if (event.getTransition().getDestination() == ReplicationState.IDLE) {
4633+
if (event.getTransition() != null &&
4634+
event.getTransition().getDestination() == ReplicationState.IDLE) {
46384635
idleSignal1.countDown();
46394636
idleSignal2.countDown();
46404637
}

0 commit comments

Comments
 (0)