Skip to content

Commit

Permalink
【Unit Test】FailbackRegistry Test: recover method (apache#2591)
Browse files Browse the repository at this point in the history
* FailbackRegistry Test: recover method

* fix the type error, and use CountDownLatch await method to fix the unstable problom

* trigger the travis ci test retry

* trigger the code static check again
  • Loading branch information
tswstarplanet authored and CrazyHZM committed Dec 6, 2018
1 parent 01cef05 commit 4169825
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.registry.NotifyListener;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -180,6 +181,28 @@ public void notify(List<URL> urls) {
assertEquals(2, count.get());
}

@Test
public void testRecover() throws Exception {
CountDownLatch countDownLatch = new CountDownLatch(4);
final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false);
NotifyListener listener = new NotifyListener() {
@Override
public void notify(List<URL> urls) {
notified.set(Boolean.TRUE);
}
};

MockRegistry mockRegistry = new MockRegistry(registryUrl, countDownLatch);
mockRegistry.register(serviceUrl);
mockRegistry.subscribe(serviceUrl, listener);
Assert.assertEquals(1, mockRegistry.getRegistered().size());
Assert.assertEquals(1, mockRegistry.getSubscribed().size());
mockRegistry.recover();
countDownLatch.await();
Assert.assertEquals(0, mockRegistry.getFailedRegistered().size());
Assert.assertEquals(null, mockRegistry.getFailedSubscribed().get(registryUrl));
Assert.assertEquals(countDownLatch.getCount(), 0);
}

private static class MockRegistry extends FailbackRegistry {
CountDownLatch latch;
Expand Down

0 comments on commit 4169825

Please sign in to comment.