@Test public void fireFailureListenerWithMetadata() { HollowProducer producer = createInMemoryProducer(); /// initialize the data -- classic producer creates the first state in the delta chain. initializeData(producer); FakeIncrementalCycleListener listener = new FakeIncrementalCycleListener(); HollowProducer fakeHollowProducer = FakeHollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .withVersionMinter(new TestVersionMinter()) .build(); HollowProducer fakeHollowProducerSpy = Mockito.spy(fakeHollowProducer); /// now we'll be incrementally updating the state by mutating individual records HollowIncrementalProducer incrementalProducer = HollowIncrementalProducer .withProducer(fakeHollowProducerSpy) .withListener(listener) .build(); HashMap<String, Object> cycleMetadata = new HashMap<>(); cycleMetadata.put("foo", "bar"); incrementalProducer.addAllCycleMetadata(cycleMetadata); Assert.assertTrue(incrementalProducer.hasMetadata()); incrementalProducer.addOrModify(new TypeA(1, "one", 100)); Mockito.doThrow(new RuntimeException("oops")).when(fakeHollowProducerSpy).runCycle(any(HollowProducer.Populator.class)); incrementalProducer.runCycle(); Assert.assertEquals(IncrementalCycleListener.Status.FAIL, listener.getStatus()); Assert.assertEquals(cycleMetadata, listener.getCycleMetadata()); Assert.assertFalse(incrementalProducer.hasMetadata()); }
.withProducer(producer) .withListener(listener) .build();
@Test public void fireFailureListener() { HollowProducer producer = createInMemoryProducer(); /// initialize the data -- classic producer creates the first state in the delta chain. initializeData(producer); FakeIncrementalCycleListener listener = new FakeIncrementalCycleListener(); HollowProducer fakeHollowProducer = FakeHollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .withVersionMinter(new TestVersionMinter()) .build(); HollowProducer fakeHollowProducerSpy = Mockito.spy(fakeHollowProducer); /// now we'll be incrementally updating the state by mutating individual records HollowIncrementalProducer incrementalProducer = HollowIncrementalProducer .withProducer(fakeHollowProducerSpy) .withListener(listener) .build(); incrementalProducer.addOrModify(new TypeA(1, "one", 100)); incrementalProducer.addOrModify(new TypeA(2, "two", 2)); incrementalProducer.addOrModify(new TypeA(3, "three", 300)); incrementalProducer.addOrModify(new TypeA(3, "three", 3)); incrementalProducer.addOrModify(new TypeA(4, "five", 6)); incrementalProducer.delete(new TypeA(5, "five", 5)); Mockito.doThrow(new RuntimeException("oops")).when(fakeHollowProducerSpy).runCycle(any(HollowProducer.Populator.class)); long nextVersion = incrementalProducer.runCycle(); Assert.assertEquals(nextVersion, listener.getVersion()); Assert.assertEquals(IncrementalCycleListener.Status.FAIL, listener.getStatus()); Assert.assertEquals(4L, listener.getRecordsAddedOrModified()); Assert.assertEquals(1L, listener.getRecordsRemoved()); Assert.assertNotNull(listener.getCause()); }
.withAnnouncementWatcher(new FakeAnnouncementWatcher(originalVersion)) .withDataModel(TypeA.class, TypeB.class) .build();
.withProducer(producer) .withListener(listener) .build();
@Test public void addsListenersAfterInitialization() { HollowProducer producer = createInMemoryProducer(); initializeData(producer); FakeIncrementalCycleListener listener = new FakeIncrementalCycleListener(); HollowIncrementalProducer incrementalProducer = HollowIncrementalProducer .withProducer(producer) .build(); //Adding the listener after initialization incrementalProducer.addListener(listener); incrementalProducer.addOrModify(new TypeA(1, "one", 100)); /// .runCycle() flushes the changes to a new data state. long nextVersion = incrementalProducer.runCycle(); Assert.assertEquals(nextVersion, listener.getVersion()); Assert.assertEquals(IncrementalCycleListener.Status.SUCCESS, listener.getStatus()); Assert.assertEquals(1L, listener.getRecordsAddedOrModified()); Assert.assertNull(listener.getCause()); }
@Test(expected = NullPointerException.class) public void failsWhenNotEnoughArgs() { HollowProducer backingProducer = HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .build(); //No AnnouncementWatcher, BlobRetriever and DataModel to restore HollowIncrementalProducer incrementalProducer = HollowIncrementalProducer.withProducer(backingProducer) .build(); incrementalProducer.restoreFromLastState(); }
@Test(expected = IllegalArgumentException.class) public void failsWithNoProducer() { //No Hollow Producer HollowIncrementalProducer.withProducer(null) .build(); }
@Test(expected = RuntimeException.class) public void failsWhenLastStateIsNotAvailable() { HollowProducer backingProducer = HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .build(); HollowIncrementalProducer incrementalProducer = HollowIncrementalProducer.withProducer(backingProducer) .withBlobRetriever(blobStore) .withAnnouncementWatcher(new FakeAnnouncementWatcher(0)) .withDataModel(TypeA.class, TypeB.class) .build(); incrementalProducer.restoreFromLastState(); }