public HollowIncrementalProducer build() { checkArguments(); return new HollowIncrementalProducer(producer, threadsPerCpu, announcementWatcher, blobRetriever, listeners, dataModel); } }
@Test public void removeAndPublishUsingMultithreading() { // run within a loop to increase the likelihood of a race condition to occur for (int iterationCounter = 0; iterationCounter < ITERATIONS; ++iterationCounter) { 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, THREADS); int[] notModifiedElementIds = IntStream.range(0, ELEMENTS / 2).toArray(); int[] deletedElementIds = IntStream.range(ELEMENTS / 2, ELEMENTS).toArray(); incrementalProducer.delete(Arrays.stream(deletedElementIds).mapToObj(i -> new SimpleType(i, i)).collect(Collectors.toList())); /// .runCycle() flushes the changes to a new data state. long versionAfterDelete = incrementalProducer.runCycle(); /// now we read the changes and assert HollowPrimaryKeyIndex idx = createPrimaryKeyIndex(versionAfterDelete); Assert.assertTrue(Arrays.stream(notModifiedElementIds) .boxed() .map(elementId -> getHollowObject(idx, elementId)) .allMatch(obj -> obj.getInt("value") == obj.getInt("id"))); Assert.assertTrue(Arrays.stream(deletedElementIds) .boxed() .map(elementId -> getOrdinal(idx, elementId)) .allMatch(ordinal -> ordinal == -1)); } }
@Test public void updateAndPublishUsingMultithreading() { // run within a loop to increase the likelihood of a race condition to occur for (int iterationCounter = 0; iterationCounter < ITERATIONS; ++iterationCounter) { 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, THREADS); int[] notModifiedElementIds = IntStream.range(0, ELEMENTS / 2).toArray(); int[] modifiedElementIds = IntStream.range(ELEMENTS / 2, ELEMENTS).toArray(); incrementalProducer.addOrModify(Arrays.stream(modifiedElementIds).mapToObj(i -> new SimpleType(i, i + 1)).collect(Collectors.toList())); /// .runCycle() flushes the changes to a new data state. long versionAfterUpdate = incrementalProducer.runCycle(); /// now we read the changes and assert HollowPrimaryKeyIndex idx = createPrimaryKeyIndex(versionAfterUpdate); Assert.assertFalse(idx.containsDuplicates()); Assert.assertTrue(Arrays.stream(notModifiedElementIds) .boxed() .map(elementId -> getHollowObject(idx, elementId)) .allMatch(obj -> obj.getInt("value") == obj.getInt("id"))); Assert.assertTrue(Arrays.stream(modifiedElementIds) .boxed() .map(elementId -> getHollowObject(idx, elementId)) .allMatch(obj -> obj.getInt("value") != obj.getInt("id"))); } }
@Test public void removeOrphanObjectsWithoutTypeInDelta() { HollowProducer producer = createInMemoryProducer(); producer.initializeDataModel(TypeC.class); producer.runCycle(new Populator() { public void populate(WriteState state) throws Exception { state.add(new TypeA(1, "one", 1)); } }); HollowIncrementalProducer incrementalProducer = new HollowIncrementalProducer(producer); TypeD typeD2 = new TypeD(2, "two"); TypeC typeC2 = new TypeC(2, typeD2); incrementalProducer.addOrModify(typeC2); incrementalProducer.runCycle(); TypeD typeD3 = new TypeD(3, "three"); typeC2 = new TypeC(2, typeD3); //Modify typeC2 to point to a new TypeD object incrementalProducer.addOrModify(typeC2); //Cycle writes a snapshot long finalVersion = incrementalProducer.runCycle(); HollowConsumer consumer = HollowConsumer.withBlobRetriever(blobStore).build(); consumer.triggerRefreshTo(finalVersion); Collection<HollowObject> allHollowObjectsTypeD = getAllHollowObjects(consumer, "TypeD"); List<String> finalTypeDNames = new ArrayList<>(); for (HollowObject hollowObject : allHollowObjectsTypeD) { finalTypeDNames.add(((GenericHollowObject) hollowObject).getObject("value").toString()); } Assert.assertFalse(finalTypeDNames.contains("two")); }
HollowIncrementalProducer incrementalProducer = new HollowIncrementalProducer(producer);
HollowIncrementalProducer incrementalProducer = new HollowIncrementalProducer(producer); incrementalProducer.addOrModify(new TypeA(11, "eleven", 11)); incrementalProducer.runCycle();
HollowIncrementalProducer incrementalProducer = new HollowIncrementalProducer(producer); incrementalProducer.addOrModify(new TypeA(2, "two", 100)); incrementalProducer.runCycle();
HollowIncrementalProducer incrementalProducer = new HollowIncrementalProducer(producer);
HollowIncrementalProducer incrementalProducer = new HollowIncrementalProducer(producer);
@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()); }
HollowIncrementalProducer incrementalProducer = new HollowIncrementalProducer(producer);
HollowIncrementalProducer incrementalProducer = new HollowIncrementalProducer(producer);
HollowIncrementalProducer incrementalProducer = new HollowIncrementalProducer(producer);
HollowIncrementalProducer incrementalProducer = new HollowIncrementalProducer(backingProducer); incrementalProducer.restore(originalVersion, blobStore);
HollowIncrementalProducer incrementalProducer = new HollowIncrementalProducer(producer);
HollowIncrementalProducer incrementalProducer = new HollowIncrementalProducer(producer);
HollowIncrementalProducer incrementalProducer = new HollowIncrementalProducer(createInMemoryProducer()); backingProducer.restore(nextVersion, blobStore); HollowIncrementalProducer incrementalProducer2 = new HollowIncrementalProducer(backingProducer);
HollowIncrementalProducer incrementalProducer = new HollowIncrementalProducer(producer);
HollowIncrementalProducer incrementalProducer = new HollowIncrementalProducer(producer, 2.0d);
HollowIncrementalProducer incrementalProducer = new HollowIncrementalProducer(producer);