@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()); }
incrementalProducer.addCycleMetadata("key3", "baz"); incrementalProducer.addOrModify(new TypeA(1, "one", 100)); Assert.assertFalse(incrementalProducer.hasMetadata()); incrementalProducer.addOrModify(new TypeA(1, "one", 1000)); incrementalProducer.runCycle(); Assert.assertEquals(new HashMap<String, Object>(), listener.getCycleMetadata());
@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()); }
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)); incrementalProducer.addOrModify(new TypeA(1, "one", 1000));
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)); incrementalProducer.addOrModify(new TypeB(5, "6")); incrementalProducer.delete(new RecordPrimaryKey("TypeB", new Object[]{3})); incrementalProducer.addOrModify(new TypeA(4, "four", 4)); incrementalProducer.addOrModify(new TypeA(1, "one", 1000));
incrementalProducer.addOrModify(new TypeA(11, "eleven", 11)); incrementalProducer.runCycle(); 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(10, "ten", 100)); long version = incrementalProducer.runCycle();
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));
.build(); incrementalProducer.addOrModify(new TypeA(1, "one", 100)); incrementalProducer.addOrModify(new TypeA(2, "two", 2)); incrementalProducer.addOrModify(new TypeA(3, "three", 300)); incrementalProducer.delete(new TypeA(5, "five", 5)); Assert.assertNull(listener.getCause()); incrementalProducer.addOrModify(new TypeA(1, "one", 1000));
incrementalProducer.addIfAbsent(new TypeA(100, "one hundred", 9999)); // new incrementalProducer.addIfAbsent(new TypeA(101, "one hundred and one", 9998)); // new incrementalProducer.addIfAbsent(new TypeA(1, "one", 9997)); // exists in prior state incrementalProducer.addIfAbsent(new TypeA(2, "two", 9996)); // exists in prior state incrementalProducer.addOrModify(new TypeA(102, "one hundred and two", 9995)); // new incrementalProducer.addIfAbsent(new TypeA(102, "one hundred and two", 9994)); // new, but already added incrementalProducer.addIfAbsent(new TypeA(103, "one hundred and three", 9993)); // new incrementalProducer.addOrModify(new TypeA(103, "one hundred and three", 9992)); // overwrites prior call to addIfAbsent
@Test public void clearMutations() { HollowProducer producer = createInMemoryProducer(); /// initialize the data -- classic producer creates the first state in the delta chain. initializeData(producer); /// now we'll be incrementally updating the state by mutating individual records HollowIncrementalProducer incrementalProducer = new HollowIncrementalProducer(producer); 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)); incrementalProducer.delete(new TypeB(2, "3")); incrementalProducer.addOrModify(new TypeB(5, "5")); incrementalProducer.addOrModify(new TypeB(5, "6")); incrementalProducer.delete(new RecordPrimaryKey("TypeB", new Object[]{3})); Assert.assertTrue(incrementalProducer.hasChanges()); /// .runCycle() flushes the changes to a new data state. incrementalProducer.runCycle(); Assert.assertFalse(incrementalProducer.hasChanges()); }
@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()); }
public void populate(WriteState state) throws Exception { state.add(new TypeA(1, "one", 1)); } });
public void populate(WriteState state) throws Exception { state.add(new TypeA(1, "one", 1)); } });
public void populate(WriteState state) throws Exception { state.add(new TypeA(1, "one", 1)); } });
public void populate(WriteState state) throws Exception { state.add(new TypeA(1, "one", 1)); state.add(new TypeA(2, "two", 2)); state.add(new TypeA(3, "three", 3)); state.add(new TypeA(4, "four", 4)); state.add(new TypeA(5, "five", 5)); state.add(new TypeB(1, "1")); state.add(new TypeB(2, "2")); state.add(new TypeB(3, "3")); state.add(new TypeB(4, "4")); } });