コード例 #1
0
  @Test
  public void testListenerErrorCanRestartReplication()
      throws URISyntaxException, InterruptedException {
    Listener listener = new Listener();

    URI uri = new URI("http://127.0.0.1:5984/db1");
    DatastoreExtended mockDatastore = mock(DatastoreExtended.class);
    ReplicationStrategy mockStrategy = mock(ReplicationStrategy.class);
    when(mockStrategy.isReplicationTerminated()).thenReturn(true);
    when(mockStrategy.getEventBus()).thenReturn(new EventBus());

    PullReplication pull = createPullReplication(uri, mockDatastore);
    TestReplicator replicator = new TestReplicator(pull, mockStrategy);
    replicator.getEventBus().register(listener);
    replicator.start();

    // Waits for callbacks to be run
    replicator.error(
        new ReplicationStrategyErrored(
            mockStrategy, new ErrorInfo(new RuntimeException("Mocked error"))));

    Assert.assertTrue(listener.run);
    Assert.assertFalse(listener.errorThrown);

    // Don't leave threads about the place
    replicator.complete(new ReplicationStrategyCompleted(mockStrategy));
  }
コード例 #2
0
  @Before
  public void setUp() throws Exception {
    uri = new URI("http://127.0.0.1:5984/db1");
    mockDatastore = mock(DatastoreExtended.class);
    mockStrategy = mock(ReplicationStrategy.class);
    when(mockStrategy.getEventBus()).thenReturn(new EventBus());
    mockListener = mock(Listener.class);
    replicator =
        new TestReplicator(this.createPullReplication(this.uri, this.mockDatastore), mockStrategy);

    // mockStrategy always needs to be ready to start
    when(mockStrategy.isReplicationTerminated()).thenReturn(true);
  }