Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunjeet committed Feb 6, 2025
1 parent 045ab77 commit 9d12f05
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public void setUp() {
schema.addField("stringField", HollowObjectSchema.FieldType.STRING);
schema.addField("intField", HollowObjectSchema.FieldType.INT);
schema.addField("doubleField", HollowObjectSchema.FieldType.DOUBLE);

super.setUp();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.netflix.hollow.api.consumer.HollowConsumer;
import com.netflix.hollow.api.producer.HollowProducer;
import com.netflix.hollow.api.producer.fs.HollowInMemoryBlobStager;
import com.netflix.hollow.core.read.engine.HollowBlobReader;
import com.netflix.hollow.core.read.engine.HollowReadStateEngine;
import com.netflix.hollow.core.read.engine.PopulatedOrdinalListener;
import com.netflix.hollow.core.read.engine.object.HollowObjectTypeReadState;
import com.netflix.hollow.core.read.iterator.HollowOrdinalIterator;
Expand Down Expand Up @@ -97,7 +99,7 @@ public void testJoinDifferentFieldWidths() throws IOException {
}

@Test
public void testLopsidedStatsShards() {
public void testLopsidedStatsShards() throws IOException {
InMemoryBlobStore blobStore = new InMemoryBlobStore();
HollowProducer p = HollowProducer.withPublisher(blobStore)
.withBlobStager(new HollowInMemoryBlobStager())
Expand Down Expand Up @@ -153,6 +155,12 @@ public int maxDeltasBeforeDoubleSnapshot() {
assertEquals(8, dataElements1.totalNumberOfElements);
assertEquals(7, dataElements1.maxOrdinal);

// v2 snapshot was also serialized with same numShards as delta
HollowReadStateEngine testSnapshot = new HollowReadStateEngine();
HollowBlobReader reader = new HollowBlobReader(testSnapshot);
reader.readSnapshot(blobStore.retrieveSnapshotBlob(v2).getInputStream());
assertEquals(2, testSnapshot.getTypeState("TestList").numShards());

long v3 = oneRunCycle(p, new int[][] {{0}, {16}});
c.triggerRefreshTo(v3);
assertEquals(2, c.getStateEngine().getTypeState("TestList").numShards());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.netflix.hollow.api.consumer.HollowConsumer;
import com.netflix.hollow.api.producer.HollowProducer;
import com.netflix.hollow.api.producer.fs.HollowInMemoryBlobStager;
import com.netflix.hollow.core.read.engine.HollowBlobReader;
import com.netflix.hollow.core.read.engine.HollowReadStateEngine;
import com.netflix.hollow.core.write.HollowMapWriteRecord;
import com.netflix.hollow.core.write.HollowObjectWriteRecord;
import com.netflix.hollow.core.write.HollowWriteStateEngine;
Expand Down Expand Up @@ -120,7 +122,7 @@ public void testJoinDifferentFieldWidths() throws IOException {
}

@Test
public void testLopsidedStatsShards() {
public void testLopsidedStatsShards() throws IOException {
InMemoryBlobStore blobStore = new InMemoryBlobStore();
HollowProducer p = HollowProducer.withPublisher(blobStore)
.withBlobStager(new HollowInMemoryBlobStager())
Expand Down Expand Up @@ -174,6 +176,12 @@ public int maxDeltasBeforeDoubleSnapshot() {
c.triggerRefreshTo(v2);
assertEquals(2, c.getStateEngine().getTypeState("TestMap").numShards());

// v2 snapshot was also serialized with same numShards as delta
HollowReadStateEngine testSnapshot = new HollowReadStateEngine();
HollowBlobReader reader = new HollowBlobReader(testSnapshot);
reader.readSnapshot(blobStore.retrieveSnapshotBlob(v2).getInputStream());
assertEquals(2, testSnapshot.getTypeState("TestMap").numShards());

HollowMapTypeDataElements dataElements0 = (HollowMapTypeDataElements) c.getStateEngine().getTypeState("TestMap").getShardsVolatile().getShards()[0].getDataElements();
HollowMapTypeDataElements dataElements1 = (HollowMapTypeDataElements) c.getStateEngine().getTypeState("TestMap").getShardsVolatile().getShards()[1].getDataElements();
assertEquals(1, dataElements0.maxOrdinal); // non-similar stats thanks to withSkipTypeShardUpdateWithNoAdditions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.netflix.hollow.api.consumer.HollowConsumer;
import com.netflix.hollow.api.producer.HollowProducer;
import com.netflix.hollow.api.producer.fs.HollowInMemoryBlobStager;
import com.netflix.hollow.core.read.engine.HollowBlobReader;
import com.netflix.hollow.core.read.engine.HollowReadStateEngine;
import com.netflix.hollow.core.write.HollowObjectWriteRecord;
import com.netflix.hollow.test.InMemoryBlobStore;
import java.io.IOException;
Expand Down Expand Up @@ -77,7 +79,7 @@ public void testJoinDifferentFieldWidths() throws IOException {

// tests data integrity and delta chain traversal when re-sharding in the presence of lopsided shards (different maxOrdinals)
@Test
public void testLopsidedMaxOrdinalShards() {
public void testLopsidedMaxOrdinalShards() throws IOException {
InMemoryBlobStore blobStore = new InMemoryBlobStore();
HollowProducer p = HollowProducer.withPublisher(blobStore)
.withBlobStager(new HollowInMemoryBlobStager())
Expand Down Expand Up @@ -113,6 +115,12 @@ public int maxDeltasBeforeDoubleSnapshot() {
c.triggerRefreshTo(v2);
assertEquals(2, c.getStateEngine().getTypeState("TestObject").numShards());

// v2 snapshot was also serialized with same numShards as delta
HollowReadStateEngine testSnapshot = new HollowReadStateEngine();
HollowBlobReader reader = new HollowBlobReader(testSnapshot);
reader.readSnapshot(blobStore.retrieveSnapshotBlob(v2).getInputStream());
assertEquals(2, testSnapshot.getTypeState("TestObject").numShards());

long v3 = oneRunCycle(p, new int[] { 0, 1, 3, 5}); // drop to 1 ordinal per shard, skipTypeShardWithNoAdds will make it so that maxOrdinal is adjusted
c.triggerRefreshTo(v3);
assertEquals(2, c.getStateEngine().getTypeState("TestObject").numShards());
Expand Down

0 comments on commit 9d12f05

Please sign in to comment.