private HollowProducer createInMemoryProducer() { return HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .build(); }
private HollowProducer createInMemoryProducer() { return HollowProducer.withPublisher(blobStore).withBlobStager(new HollowInMemoryBlobStager()).build(); }
private static HollowProducer getProducer(ObjectModificationValidator validator) { return HollowProducer.withPublisher(new InMemoryBlobStore()) .withBlobStager(new HollowInMemoryBlobStager()) .withListener(validator) .build(); }
@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 public void producerRestoresAndProducesDelta() { HollowProducer producer = HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .build(); long v1 = runCycle(producer, 1); HollowProducer redeployedProducer = HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .build(); redeployedProducer.initializeDataModel(Integer.class); redeployedProducer.restore(v1, blobStore); long v2 = runCycle(producer, 2); Assert.assertNotNull(blobStore.retrieveDeltaBlob(v1)); Assert.assertEquals(v2, blobStore.retrieveDeltaBlob(v1).getToVersion()); }
@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()); }
@Test public void testNullMetricsCollector() { HollowProducer producer = HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .build(); long version = producer.runCycle(new HollowProducer.Populator() { public void populate(HollowProducer.WriteState state) throws Exception { state.add(Integer.valueOf(1)); } }); HollowConsumer consumer = HollowConsumer.withBlobRetriever(blobStore) .withMetricsCollector(null) .build(); consumer.triggerRefreshTo(version); }
@Test public void failTestTooManyRemoved() { try { HollowProducer producer = HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .withListener(new RecordCountVarianceValidator("TypeWithPrimaryKey", 1f)).build(); producer.runCycle(new Populator() { public void populate(WriteState newState) throws Exception { newState.add(new TypeWithPrimaryKey(1, "Brad Pitt", "klsdjfla;sdjkf")); newState.add(new TypeWithPrimaryKey(1, "Angelina Jolie", "as;dlkfjasd;l")); } }); producer.runCycle(new Populator() { public void populate(WriteState newState) throws Exception { newState.add(new TypeWithPrimaryKey(1, "Brad Pitt", "klsdjfla;sdjkf")); newState.add(new TypeWithPrimaryKey(1, "Angelina Jolie", "as;dlkfjasd;l")); newState.add(new TypeWithPrimaryKey(1, "Bruce Willis", "as;dlkfjasd;l")); } }); Assert.fail(); } catch (ValidationStatusException expected) { //System.out.println("Message:"+expected.getIndividualFailures().get(0).getMessage()); Assert.assertEquals(1, expected.getValidationStatus().getResults().size()); Assert.assertTrue(expected.getValidationStatus().getResults().get(0).getMessage() .startsWith("Record count validation for type")); } }
try { HollowProducer producer = HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .withListener(new RecordCountVarianceValidator("TypeWithPrimaryKey", 1f)).build();
@Test public void publishAndLoadASnapshot() { HollowProducer producer = HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .build(); /// Showing verbose version of `runCycle(producer, 1);` long version = producer.runCycle(state -> state.add(1)); HollowConsumer consumer = HollowConsumer.withBlobRetriever(blobStore).build(); consumer.triggerRefreshTo(version); Assert.assertEquals(version, consumer.getCurrentVersionId()); }
@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(); }
@Test public void producerValidatesWithError() { HollowProducer producer = HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .withListener(new ValidatorListener() { @Override public String getName() {
void duplicateDetectionFailureTest(DuplicateDataDetectionValidator v, boolean auto) { HollowProducer.Builder<?> b = HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()); if (v != null) { b.withListener(v); } HollowProducer producer = b.build(); if (auto) { producer.initializeDataModel(TypeWithPrimaryKey.class); DuplicateDataDetectionValidator.addValidatorsForSchemaWithPrimaryKey(producer); } try { //runCycle(producer, 1); producer.runCycle(newState -> { newState.add(new TypeWithPrimaryKey(1, "Brad Pitt", "klsdjfla;sdjkf")); newState.add(new TypeWithPrimaryKey(1, "Angelina Jolie", "as;dlkfjasd;l")); newState.add(new TypeWithPrimaryKey(1, "Brad Pitt", "as;dlkfjasd;l")); }); Assert.fail(); } catch (ValidationStatusException expected) { Assert.assertEquals(1, expected.getValidationStatus().getResults().size()); Assert.assertTrue(expected.getValidationStatus().getResults().get(0).getMessage() .startsWith("Duplicate keys found for type TypeWithPrimaryKey")); } }
@Test public void producerCompacts() { HollowProducer producer = HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .build();
@Test public void producerUsesCustomVersionMinter() { HollowProducer producer = HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .withVersionMinter(new VersionMinter() { long counter = 0; public long mint() { return ++counter; } }) .build(); long v1 = runCycle(producer, 1); long v2 = runCycle(producer, 2); long v3 = runCycle(producer, 3); Assert.assertEquals(1, v1); Assert.assertEquals(2, v2); Assert.assertEquals(3, v3); }
@Test public void producerValidatesWithFailure() { HollowProducer producer = HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .withListener(new ValidatorListener() { @Override public String getName() {
@Before public void setUp() { blobStore = new InMemoryBlobStore(); listener = new RecordingRefreshListener(); producer = HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .withNumStatesBetweenSnapshots(Integer.MAX_VALUE) .build(); consumer = HollowConsumer.withBlobRetriever(blobStore) .withRefreshListener(listener) .withObjectLongevityConfig(new ObjectLongevityConfig() { @Override public long usageDetectionPeriodMillis() { return 100L; } @Override public long gracePeriodMillis() { return 100L; } @Override public boolean forceDropData() { return false; } @Override public boolean enableLongLivedObjectSupport() { return true; } @Override public boolean enableExpiredUsageStackTraces() { return false; } @Override public boolean dropDataAutomatically() { return true; } }) .build(); }
@Before public void setUp() { mapper = new HollowObjectMapper(new HollowWriteStateEngine()); mapper.initializeTypeState(TypeA.class); mapper.initializeTypeState(TypeC.class); schemaIdMapper = new FakeHollowSchemaIdentifierMapper(mapper.getStateEngine()); blobStore = new InMemoryBlobStore(); flatRecordWriter = new FlatRecordWriter(mapper.getStateEngine(), schemaIdMapper); producer = HollowProducer.withPublisher(blobStore).withBlobStager(new HollowInMemoryBlobStager()).build(); }
@Test public void passTestNoMoreChangeThanExpected() { HollowProducer producer = HollowProducer.withPublisher(blobStore).withBlobStager(new HollowInMemoryBlobStager()) .withListener(new RecordCountVarianceValidator("TypeWithPrimaryKey", 50f)).build(); // runCycle(producer, 1); producer.runCycle(new Populator() { public void populate(WriteState newState) throws Exception { newState.add(new TypeWithPrimaryKey(1, "Brad Pitt", "klsdjfla;sdjkf")); newState.add(new TypeWithPrimaryKey(1, "Angelina Jolie", "as;dlkfjasd;l")); } }); producer.runCycle(new Populator() { public void populate(WriteState newState) throws Exception { newState.add(new TypeWithPrimaryKey(1, "Brad Pitt", "klsdjfla;sdjkf")); newState.add(new TypeWithPrimaryKey(2, "Angelina Jolie", "as;dlkfjasd;l")); newState.add(new TypeWithPrimaryKey(7, "Bruce Willis", "as;dlkfjasd;l")); } }); HollowConsumer consumer = HollowConsumer.withBlobRetriever(blobStore).build(); consumer.triggerRefresh(); Assert.assertEquals(3, consumer.getStateEngine().getTypeState("TypeWithPrimaryKey").getPopulatedOrdinals() .cardinality()); }
@Test public void duplicateDetectionSuccessTest() { HollowProducer producer = HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .withListener(new DuplicateDataDetectionValidator("TypeWithPrimaryKey")) .build(); //runCycle(producer, 1); producer.runCycle(newState -> { newState.add(new TypeWithPrimaryKey(1, "Brad Pitt", "klsdjfla;sdjkf")); newState.add(new TypeWithPrimaryKey(1, "Angelina Jolie", "as;dlkfjasd;l")); }); HollowConsumer consumer = HollowConsumer.withBlobRetriever(blobStore).build(); consumer.triggerRefresh(); Assert.assertEquals(2, consumer.getStateEngine().getTypeState("TypeWithPrimaryKey").getPopulatedOrdinals() .cardinality()); }