Skip to content

Commit

Permalink
Refactor tests for polymorphism
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunjeet committed Aug 20, 2024
1 parent 3767beb commit 77b8ec6
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.netflix.hollow.core.write.objectmapper.TypeA;
import com.netflix.hollow.core.write.objectmapper.TypeB;
import com.netflix.hollow.core.write.objectmapper.TypeC;
import com.netflix.hollow.test.InMemoryBlobStore;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
Expand All @@ -43,8 +44,6 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;

import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.netflix.hollow.core.read.engine;

import com.netflix.hollow.core.AbstractStateEngineTest;
import com.netflix.hollow.core.schema.HollowObjectSchema;
import com.netflix.hollow.core.write.HollowObjectTypeWriteState;
import com.netflix.hollow.core.write.HollowObjectWriteRecord;
import org.junit.Before;

public class AbstractHollowTypeDataElementsSplitJoinTest extends AbstractStateEngineTest {
protected HollowObjectSchema schema;

@Before
public void setUp() {
schema = new HollowObjectSchema("TestObject", 4);
schema.addField("longField", HollowObjectSchema.FieldType.LONG);
schema.addField("stringField", HollowObjectSchema.FieldType.STRING);
schema.addField("intField", HollowObjectSchema.FieldType.INT);
schema.addField("doubleField", HollowObjectSchema.FieldType.DOUBLE);

super.setUp();
}

@Override
protected void initializeTypeStates() {
writeStateEngine.addTypeState(new HollowObjectTypeWriteState(schema));
}

protected void populateWriteStateEngine(int numRecords) {
initWriteStateEngine();
HollowObjectWriteRecord rec = new HollowObjectWriteRecord(schema);
for(int i=0;i<numRecords;i++) {
rec.reset();
rec.setLong("longField", i);
rec.setString("stringField", "Value" + i);
rec.setInt("intField", i);
rec.setDouble("doubleField", i);

writeStateEngine.add("TestObject", rec);
}
}

protected void populateWriteStateEngine(int[] recordIds) {
initWriteStateEngine();
HollowObjectWriteRecord rec = new HollowObjectWriteRecord(schema);
for(int recordId : recordIds) {
rec.reset();
rec.setLong("longField", recordId);
rec.setString("stringField", "Value" + recordId);
rec.setInt("intField", recordId);
rec.setDouble("doubleField", recordId);

writeStateEngine.add("TestObject", rec);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,83 +2,43 @@

import static org.mockito.Mockito.when;

import com.netflix.hollow.core.AbstractStateEngineTest;
import com.netflix.hollow.core.read.engine.HollowReadStateEngine;
import com.netflix.hollow.core.read.filter.HollowFilterConfig;
import com.netflix.hollow.core.read.engine.AbstractHollowTypeDataElementsSplitJoinTest;
import com.netflix.hollow.core.read.iterator.HollowOrdinalIterator;
import com.netflix.hollow.core.schema.HollowListSchema;
import com.netflix.hollow.core.schema.HollowObjectSchema;
import com.netflix.hollow.core.util.StateEngineRoundTripper;
import com.netflix.hollow.core.write.HollowListTypeWriteState;
import com.netflix.hollow.core.write.HollowListWriteRecord;
import com.netflix.hollow.core.write.HollowObjectTypeWriteState;
import com.netflix.hollow.core.write.HollowObjectWriteRecord;
import java.io.IOException;
import java.util.Arrays;
import org.junit.Assert;
import org.junit.Before;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

public class AbstractHollowListTypeDataElementsSplitJoinTest extends AbstractStateEngineTest {
protected HollowObjectSchema objectSchema;
public class AbstractHollowListTypeDataElementsSplitJoinTest extends AbstractHollowTypeDataElementsSplitJoinTest {
protected HollowListSchema listSchema;

@Mock
protected HollowListTypeReadState mockListTypeState;

@Before
public void setUp() {
this.objectSchema = new HollowObjectSchema("TestObject", 4);
this.objectSchema.addField("longField", HollowObjectSchema.FieldType.LONG);
this.objectSchema.addField("stringField", HollowObjectSchema.FieldType.STRING);
this.objectSchema.addField("intField", HollowObjectSchema.FieldType.INT);
this.objectSchema.addField("doubleField", HollowObjectSchema.FieldType.DOUBLE);

this.listSchema = new HollowListSchema("TestList", "TestObject");

super.setUp();

MockitoAnnotations.initMocks(this);
HollowListTypeDataElements[] fakeDataElements = new HollowListTypeDataElements[5];
when(mockListTypeState.currentDataElements()).thenReturn(fakeDataElements);
super.setUp();
}

@Override
protected void initializeTypeStates() {
writeStateEngine.setTargetMaxTypeShardSize(4096);
writeStateEngine.addTypeState(new HollowObjectTypeWriteState(objectSchema));
super.initializeTypeStates();
writeStateEngine.addTypeState(new HollowListTypeWriteState(listSchema));
writeStateEngine.setTargetMaxTypeShardSize(4 * 100 * 1000 * 1024);
}

private void populateWriteStateEngine(int numRecords, int[][] listContents) {
initWriteStateEngine();
HollowObjectWriteRecord rec = new HollowObjectWriteRecord(objectSchema);
for(int i=0;i<numRecords;i++) {
rec.reset();
rec.setLong("longField", i);
rec.setString("stringField", "Value" + i);
rec.setInt("intField", i);
rec.setDouble("doubleField", i);

writeStateEngine.add("TestObject", rec);
}
for(int[] list : listContents) {
addRecord(Arrays.stream(list).toArray());
}
}

private void populateWriteStateEngine(int[] recordIds, int[][] listContents) {
initWriteStateEngine();
HollowObjectWriteRecord rec = new HollowObjectWriteRecord(objectSchema);
for(int recordId : recordIds) {
rec.reset();
rec.setLong("longField", recordId);
rec.setString("stringField", "Value" + recordId);
rec.setInt("intField", recordId);
rec.setDouble("doubleField", recordId);

writeStateEngine.add("TestObject", rec);
}
private void populateWriteStateEngine(int[][] listContents) {
for(int[] list : listContents) {
addRecord(Arrays.stream(list).toArray());
}
Expand All @@ -96,13 +56,15 @@ private void addRecord(int... ordinals) {


protected HollowListTypeReadState populateTypeStateWith(int numRecords, int[][] listContents) throws IOException {
populateWriteStateEngine(numRecords, listContents);
populateWriteStateEngine(numRecords);
populateWriteStateEngine(listContents);
roundTripSnapshot();
return (HollowListTypeReadState) readStateEngine.getTypeState("TestList");
}

protected HollowListTypeReadState populateTypeStateWith(int[] recordIds, int[][] listContents) throws IOException {
populateWriteStateEngine(recordIds, listContents);
populateWriteStateEngine(recordIds);
populateWriteStateEngine(listContents);
roundTripSnapshot();
return (HollowListTypeReadState) readStateEngine.getTypeState("TestList");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import com.netflix.hollow.core.memory.MemoryMode;
import com.netflix.hollow.core.read.engine.HollowReadStateEngine;
import com.netflix.hollow.core.schema.HollowSchema;
import com.netflix.hollow.core.write.HollowListTypeWriteState;
import com.netflix.hollow.core.write.HollowObjectTypeWriteState;
import com.netflix.hollow.tools.checksum.HollowChecksum;
import java.io.IOException;
import java.nio.file.Paths;
Expand All @@ -17,13 +15,6 @@

public class HollowListTypeDataElementsSplitJoinTest extends AbstractHollowListTypeDataElementsSplitJoinTest {

@Override
protected void initializeTypeStates() {
writeStateEngine.setTargetMaxTypeShardSize(4 * 100 * 1000 * 1024);
writeStateEngine.addTypeState(new HollowObjectTypeWriteState(objectSchema));
writeStateEngine.addTypeState(new HollowListTypeWriteState(listSchema));
}

@Test
public void testSplitThenJoin() throws IOException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,33 @@
import static org.mockito.Mockito.when;

import com.netflix.hollow.api.objects.generic.GenericHollowObject;
import com.netflix.hollow.core.AbstractStateEngineTest;
import com.netflix.hollow.core.read.engine.AbstractHollowTypeDataElementsSplitJoinTest;
import com.netflix.hollow.core.read.engine.HollowReadStateEngine;
import com.netflix.hollow.core.read.filter.HollowFilterConfig;
import com.netflix.hollow.core.schema.HollowObjectSchema;
import com.netflix.hollow.core.util.StateEngineRoundTripper;
import com.netflix.hollow.core.write.HollowObjectTypeWriteState;
import com.netflix.hollow.core.write.HollowObjectWriteRecord;
import java.io.IOException;
import org.junit.Before;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

public class AbstractHollowObjectTypeDataElementsSplitJoinTest extends AbstractStateEngineTest {
protected HollowObjectSchema schema;
public class AbstractHollowObjectTypeDataElementsSplitJoinTest extends AbstractHollowTypeDataElementsSplitJoinTest {

@Mock
protected HollowObjectTypeReadState mockObjectTypeState;

@Before
public void setUp() {
schema = new HollowObjectSchema("TestObject", 4);
schema.addField("longField", HollowObjectSchema.FieldType.LONG);
schema.addField("stringField", HollowObjectSchema.FieldType.STRING);
schema.addField("intField", HollowObjectSchema.FieldType.INT);
schema.addField("doubleField", HollowObjectSchema.FieldType.DOUBLE);
super.setUp();

MockitoAnnotations.initMocks(this);
HollowObjectTypeDataElements[] fakeDataElements = new HollowObjectTypeDataElements[5];
when(mockObjectTypeState.currentDataElements()).thenReturn(fakeDataElements);
super.setUp();
}

@Override
protected void initializeTypeStates() {
writeStateEngine.setTargetMaxTypeShardSize(4096);
writeStateEngine.addTypeState(new HollowObjectTypeWriteState(schema));
}

private void populateWriteStateEngine(int numRecords) {
initWriteStateEngine();
HollowObjectWriteRecord rec = new HollowObjectWriteRecord(schema);
for(int i=0;i<numRecords;i++) {
rec.reset();
rec.setLong("longField", i);
rec.setString("stringField", "Value" + i);
rec.setInt("intField", i);
rec.setDouble("doubleField", i);

writeStateEngine.add("TestObject", rec);
}
}

private void populateWriteStateEngine(int[] recordIds) {
initWriteStateEngine();
HollowObjectWriteRecord rec = new HollowObjectWriteRecord(schema);
for(int recordId : recordIds) {
rec.reset();
rec.setLong("longField", recordId);
rec.setString("stringField", "Value" + recordId);
rec.setInt("intField", recordId);
rec.setDouble("doubleField", recordId);

writeStateEngine.add("TestObject", rec);
}
super.initializeTypeStates();
writeStateEngine.setTargetMaxTypeShardSize(4 * 1000 * 1024);
}

protected HollowObjectTypeReadState populateTypeStateWith(int numRecords) throws IOException {
Expand All @@ -91,6 +54,8 @@ protected HollowObjectTypeReadState populateTypeStateWithFilter(int numRecords)
return (HollowObjectTypeReadState) readStateEngine.getTypeState("TestObject");
}



protected void assertDataUnchanged(int numRecords) {
assertDataUnchanged((HollowObjectTypeReadState) readStateEngine.getTypeState("TestObject"), numRecords);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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.write.HollowObjectTypeWriteState;
import com.netflix.hollow.core.write.HollowObjectWriteRecord;
import com.netflix.hollow.test.InMemoryBlobStore;
import java.io.IOException;
Expand All @@ -16,8 +15,8 @@
public class HollowObjectTypeDataElementsJoinerTest extends AbstractHollowObjectTypeDataElementsSplitJoinTest {
@Override
protected void initializeTypeStates() {
super.initializeTypeStates();
writeStateEngine.setTargetMaxTypeShardSize(16);
writeStateEngine.addTypeState(new HollowObjectTypeWriteState(schema));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.netflix.hollow.api.consumer.fs.HollowFilesystemBlobRetriever;
import com.netflix.hollow.core.read.engine.HollowReadStateEngine;
import com.netflix.hollow.core.schema.HollowSchema;
import com.netflix.hollow.core.write.HollowObjectTypeWriteState;
import com.netflix.hollow.tools.checksum.HollowChecksum;
import java.io.IOException;
import java.nio.file.Paths;
Expand All @@ -15,12 +14,6 @@

public class HollowObjectTypeDataElementsSplitJoinTest extends AbstractHollowObjectTypeDataElementsSplitJoinTest {

@Override
protected void initializeTypeStates() {
writeStateEngine.setTargetMaxTypeShardSize(4 * 1000 * 1024);
writeStateEngine.addTypeState(new HollowObjectTypeWriteState(schema));
}

@Test
public void testSplitThenJoin() throws IOException {
for (int numRecords=0;numRecords<1*1000;numRecords++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static com.netflix.hollow.core.read.engine.object.HollowObjectTypeReadState.shardingFactor;
import static junit.framework.TestCase.assertEquals;

import com.netflix.hollow.api.objects.generic.GenericHollowObject;
import com.netflix.hollow.core.memory.MemoryMode;
import com.netflix.hollow.core.write.HollowObjectTypeWriteState;
import java.util.Random;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.netflix.hollow.core.read.engine.set;

public class AbstractHollowSetTypeDataElementsSplitJoinTest { //extends AbstractHollowTypeDataElementsSplitJoinTest {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.netflix.hollow.core.read.engine.set;

public class HollowSetTypeDataElementsSplitJoinTest { //} extends AbstractHollowSetTypeDataElementsSplitJoinTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@
import com.netflix.hollow.core.read.engine.HollowReadStateEngine;
import com.netflix.hollow.core.read.engine.HollowTypeReadState;
import com.netflix.hollow.core.read.engine.map.HollowMapTypeReadState;
import com.netflix.hollow.core.read.engine.object.HollowObjectTypeReadState;
import com.netflix.hollow.core.read.iterator.HollowMapEntryOrdinalIterator;
import com.netflix.hollow.core.schema.HollowMapSchema;
import com.netflix.hollow.core.util.StateEngineRoundTripper;
import com.netflix.hollow.core.write.HollowBlobWriter;
import com.netflix.hollow.core.write.HollowMapTypeWriteState;
import com.netflix.hollow.core.write.HollowMapWriteRecord;
import com.netflix.hollow.core.write.HollowWriteStateEngine;
import com.netflix.hollow.core.write.objectmapper.HollowObjectMapper;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Assert;
Expand Down

0 comments on commit 77b8ec6

Please sign in to comment.