@Test public void testGetChangePercent() { RecordCountVarianceValidator val = new RecordCountVarianceValidator("someType", 3.0f); Assert.assertTrue((Float.compare(99.99999652463547f, val.getChangePercent(0, 28382664)) == 0)); Assert.assertTrue((Float.compare(99.646645f, val.getChangePercent(1, 283)) == 0)); }
@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();
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()); }