@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")); } }
HollowProducer producer = HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .withListener(new RecordCountVarianceValidator("TypeWithPrimaryKey", 1f)).build();
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")); } }
HollowProducer producer = HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .withListener(new ValidatorListener() { @Override public String getName() { .withListener(new ValidationStatusListener() { @Override public void onValidationStatusStart(long version) {
HollowProducer producer = HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .withListener(new ValidatorListener() { @Override public String getName() { return "Test validator"; .withListener(new ValidationStatusListener() { boolean isStartCalled;
HollowProducer producer = HollowProducer.withPublisher(blobStore) .withBlobStager(new HollowInMemoryBlobStager()) .withListener(new ValidatorListener() { @Override public String getName() { return "Test validator"; .withListener(new ValidationStatusListener() { boolean isStartCalled;
private void createHollowProducerAndRunCycle(final String typeName, boolean addPrimaryKeyValidator) { ValidatorListener dupeValidator = new DuplicateDataDetectionValidator(typeName); ValidatorListener countValidator = new RecordCountVarianceValidator(typeName, 3.0f); validationListener = new TestValidationStatusListener(); cycleAndValidationListener = new TestCycleAndValidationStatusListener(); Builder builder = HollowProducer.withPublisher(publisher).withAnnouncer(announcer) .withListener(validationListener) .withListener(cycleAndValidationListener) .withListener(countValidator); if (addPrimaryKeyValidator) { builder = builder.withListener(dupeValidator); } HollowProducer hollowProducer = builder.build(); if (typeName.equals("MovieWithPrimaryKey")) { hollowProducer.initializeDataModel(MovieWithPrimaryKey.class); } else { hollowProducer.initializeDataModel(MovieWithoutPrimaryKey.class); } hollowProducer.runCycle(newState -> { List<String> actors = Arrays.asList("Angelina Jolie", "Brad Pitt"); if (typeName.equals("MovieWithPrimaryKey")) { newState.add(new MovieWithPrimaryKey(123, "someTitle1", actors)); newState.add(new MovieWithPrimaryKey(123, "someTitle1", actors)); } else { newState.add(new MovieWithoutPrimaryKey(123, "someTitle1", actors)); newState.add(new MovieWithoutPrimaryKey(1233, "someTitle2", actors)); } }); }
@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()); }
/** * Registers a validator event listener that will receive a validator event * during the validator stage. * * @param validator the validator listener * @return this builder * @apiNote This method is equivalent to registering the listener with * {@link #withListener(HollowProducerEventListener)}. * @see #withListener(HollowProducerEventListener) */ public B withValidator(ValidatorListener validator) { return withListener(validator); }
public B withListener(HollowProducerListener listener) { return withListener((HollowProducerEventListener) listener); }
private static HollowProducer getProducer(ObjectModificationValidator validator) { return HollowProducer.withPublisher(new InMemoryBlobStore()) .withBlobStager(new HollowInMemoryBlobStager()) .withListener(validator) .build(); }