@Test public void testWithSelectGenericHollowObject() { HashIndexSelect<DataModel.Consumer.TypeA, GenericHollowObject, Integer> hi = HashIndex .from(consumer, DataModel.Consumer.TypeA.class) .selectField("s", GenericHollowObject.class) .usingPath("i", int.class); List<String> r = hi.findMatches(1) .sorted(Comparator.comparingInt(HollowObject::getOrdinal)) .map(gho -> gho.getString("value")) .collect(toList()); Assert.assertEquals(100, r.size()); for (int i = 0; i < r.size(); i++) { Assert.assertEquals("TypeA" + i, r.get(i)); } } }
@Override protected String getData(HollowObjectTypeReadState readState, int ordinal) { GenericHollowObject obj = new GenericHollowObject(new HollowObjectGenericDelegate(readState), ordinal); return obj.getString("value"); }
private void assertUpdatedList(Collection<UpdatedRecord<GenericHollowObject>> listOfObj, List<String> beforeValues, List<String> afterValues) { int i = 0; for (UpdatedRecord<GenericHollowObject> obj : listOfObj) { int beforeId = obj.getBefore().getInt("f1"); int afterId = obj.getAfter().getInt("f1"); Assert.assertEquals(beforeId, afterId); String beforeVal = beforeValues.get(i); String afterVal = afterValues.get(i++); Assert.assertNotEquals(beforeVal, afterVal); Assert.assertEquals(beforeVal, obj.getBefore().getString("f2")); Assert.assertEquals(afterVal, obj.getAfter().getString("f2")); } }
private void assertTypeAWithTypeC(int ordinal, boolean a1, String a2, String c1) { HollowObjectTypeReadState typeAState = (HollowObjectTypeReadState)readStateEngine.getTypeState("TypeA"); GenericHollowObject typeAObj = new GenericHollowObject(new HollowObjectGenericDelegate(typeAState), ordinal); Assert.assertEquals(a1, typeAObj.getBoolean("a1")); Assert.assertEquals(a2, typeAObj.getString("a2")); GenericHollowObject typeCObj = (GenericHollowObject) typeAObj.getReferencedGenericRecord("a4"); Assert.assertEquals(c1, typeCObj.getString("c1")); }
@Test public void testBuild_withTypeInitialization() { HollowReadStateEngine readEngine = new HollowReadStateEngineBuilder(Arrays.<Class<?>>asList(String.class, Long.class)) .add("foo").add(3L).build(); assertEquals("Should have both types", new HashSet<String>(Arrays.asList( String.class.getSimpleName(), Long.class.getSimpleName())), new HashSet<String>(readEngine.getAllTypes())); assertEquals("Should have one String", 1, readEngine.getTypeDataAccess( String.class.getSimpleName()).getTypeState().getPopulatedOrdinals().cardinality()); assertEquals("The one String should be foo", "foo", new GenericHollowObject(readEngine, String.class.getSimpleName(), 0).getString("value")); assertEquals("Should have one Long", 1, readEngine.getTypeDataAccess( Long.class.getSimpleName()).getTypeState().getPopulatedOrdinals().cardinality()); assertEquals("The one Long should be 3L", 3L, new GenericHollowObject(readEngine, Long.class.getSimpleName(), 0).getLong("value")); }
@Test public void testValidate_validationFailure() { BiPredicate<GenericHollowObject, GenericHollowObject> filter = (a, b) -> a.getObject("data").getString("value").length() <= b.getObject("data").getString("value").length(); ObjectModificationValidator<HollowAPI, GenericHollowObject> validator = createValidator(filter); HollowProducer producer = getProducer(validator); producer.runCycle(writeState -> writeState.add(new TypeA(1, "fo", "bar"))); try { producer.runCycle(writeState -> writeState.add(new TypeA(1, "fo", "ba"))); fail("Expected validation exception"); } catch (ValidationStatusException e) { // expected } }
private void assertObject(HollowObjectTypeReadState readState, int ordinal, int intVal, String strVal) { GenericHollowObject obj = new GenericHollowObject(new HollowObjectGenericDelegate(readState), ordinal); Assert.assertEquals(intVal, obj.getInt("f1")); Assert.assertEquals(strVal, obj.getString("f2")); }
private void assertObject(HollowObjectTypeReadState readState, int ordinal, int intVal, String strVal) { GenericHollowObject obj = new GenericHollowObject(new HollowObjectGenericDelegate(readState), ordinal); Assert.assertEquals(intVal, obj.getInt("f1")); Assert.assertEquals(strVal, obj.getString("f2")); }
private void assertObject(HollowObjectTypeReadState readState, int ordinal, int intVal, String strVal) { GenericHollowObject obj = new GenericHollowObject(new HollowObjectGenericDelegate(readState), ordinal); Assert.assertEquals(intVal, obj.getInt("f1")); Assert.assertEquals(strVal, obj.getString("f2")); }
private void assertObject(HollowObjectTypeReadState readState, int ordinal, int intVal, String strVal) { GenericHollowObject obj = new GenericHollowObject(new HollowObjectGenericDelegate(readState), ordinal); Assert.assertEquals(intVal, obj.getInt("f1")); Assert.assertEquals(strVal, obj.getString("f2")); }
private void assertObject(HollowObjectTypeReadState readState, int ordinal, int intVal, String strVal) { GenericHollowObject obj = new GenericHollowObject(new HollowObjectGenericDelegate(readState), ordinal); Assert.assertEquals(intVal, obj.getInt("f1")); Assert.assertEquals(strVal, obj.getString("f2")); }
private void assertObject(HollowObjectTypeReadState readState, int ordinal, int intVal, String strVal) { GenericHollowObject obj = new GenericHollowObject(new HollowObjectGenericDelegate(readState), ordinal); Assert.assertEquals(intVal, obj.getInt("f1")); Assert.assertEquals(strVal, obj.getString("f2")); }
private void assertTypeA(int ordinal, boolean a1, String a2) { HollowObjectTypeReadState typeState = (HollowObjectTypeReadState)readStateEngine.getTypeState("TypeA"); GenericHollowObject obj = new GenericHollowObject(new HollowObjectGenericDelegate(typeState), ordinal); Assert.assertEquals(a1, obj.getBoolean("a1")); Assert.assertEquals(a2, obj.getString("a2")); }
private void assertTypeB(HollowPrimaryKeyIndex typeBIdx, int id1, String expectedValue) { int ordinal = typeBIdx.getMatchingOrdinal(id1); if (expectedValue == null) { Assert.assertEquals(-1, ordinal); } else { Assert.assertNotEquals(-1, ordinal); GenericHollowObject obj = new GenericHollowObject( typeBIdx.getTypeState(), ordinal); Assert.assertEquals(expectedValue, obj.getObject("value") .getString("value")); } }
private void assertA(HollowReadStateEngine stateEngine, int id, String val, boolean verifyEchoes) { HollowPrimaryKeyIndex idx = new HollowPrimaryKeyIndex(stateEngine, "TypeA", "id"); int ordinal = idx.getMatchingOrdinal(id); GenericHollowObject a = (GenericHollowObject) GenericHollowRecordHelper.instantiate(stateEngine, "TypeA", ordinal); GenericHollowList bList = (GenericHollowList)a.getReferencedGenericRecord("b"); GenericHollowObject b = (GenericHollowObject)bList.get(0); GenericHollowObject str = (GenericHollowObject)b.getReferencedGenericRecord("val"); Assert.assertEquals(val, str.getString("value")); if(verifyEchoes) { Assert.assertEquals(id, a.getInt("idEcho")); Assert.assertEquals(id, b.getInt("idEcho")); } }
@Test public void testDefaultMissingObjectValue() throws IOException { addRecord(1, "one"); addRecord(2, "two"); addRecord(3, "three"); roundTripSnapshot(); GenericHollowObject obj = (GenericHollowObject) GenericHollowRecordHelper.instantiate(readStateEngine, "TestObject", 1); assertEquals(2, obj.getInt("f1")); assertEquals("two", obj.getString("f2")); assertEquals(Long.MIN_VALUE, obj.getLong("f3")); assertEquals(Integer.MIN_VALUE, obj.getInt("f4")); assertTrue(Float.isNaN(obj.getFloat("f5"))); assertTrue(Double.isNaN(obj.getDouble("f6"))); assertEquals(null, obj.getString("f7")); assertFalse(obj.isStringFieldEqual("f7", "not-null")); assertTrue(obj.isStringFieldEqual("f7", null)); assertEquals(null, obj.getBytes("f8")); assertTrue(obj.isNull("f9")); assertFalse(obj.getBoolean("f10")); }
@Test public void testAddSnapshot_data() throws Exception { long latestVersion = 1L; TestHollowConsumer consumer = new TestHollowConsumer.Builder() .withAnnouncementWatcher(new TestAnnouncementWatcher().setLatestVersion(1L)) .withBlobRetriever(new TestBlobRetriever()) .build(); consumer.addSnapshot(latestVersion, new HollowWriteStateEngineBuilder().add("foo").add(2).build()); consumer.triggerRefresh(); HollowDataAccess data = consumer.getAPI().getDataAccess(); assertEquals("Should have string and int", new HashSet<>(Arrays.asList("String", "Integer")), data.getAllTypes()); assertEquals("foo", new GenericHollowObject(data, "String", 0).getString("value")); assertEquals(2, new GenericHollowObject(data, "Integer", 0).getInt("value")); }
public TypeWithAllFieldTypes(GenericHollowObject obj) { this.bool = obj.getBoolean("bool"); this.i = obj.getInt("i"); this.b = (byte)obj.getInt("b"); this.s = (short)obj.getInt("s"); this.c = (char)obj.getInt("c"); this.l = obj.getLong("l"); this.f = obj.getFloat("f"); this.d = obj.getDouble("d"); this.inlinedBoolean = obj.isNull("inlinedBoolean") ? null : obj.getBoolean("inlinedBoolean"); this.inlinedInt = obj.isNull("inlinedInt") ? null : obj.getInt("inlinedInt"); this.inlinedByte = obj.isNull("inlinedByte") ? null : (byte)obj.getInt("inlinedByte"); this.inlinedShort = obj.isNull("inlinedShort") ? null : (short)obj.getInt("inlinedShort"); this.inlinedChar = obj.isNull("inlinedChar") ? null : (char)obj.getInt("inlinedChar"); this.inlinedLong = obj.isNull("inlinedLong") ? null : obj.getLong("inlinedLong"); this.inlinedFloat = obj.isNull("inlinedFloat") ? null : obj.getFloat("inlinedFloat"); this.inlinedDouble = obj.isNull("inlinedDouble") ? null : obj.getDouble("inlinedDouble"); this.inlinedString = obj.isNull("inlinedString") ? null : obj.getString("inlinedString"); this.charArray = obj.isNull("charArray") ? null : obj.getString("charArray").toCharArray(); this.byteArray = obj.isNull("byteArray") ? null : obj.getBytes("byteArray"); this.nullablePrimitiveBoolean = obj.isNull("nullablePrimitiveBoolean") ? null : obj.getBoolean("nullablePrimitiveBoolean") ? NullablePrimitiveBoolean.TRUE : NullablePrimitiveBoolean.FALSE; this.referencedInteger = obj.isNull("referencedInteger") ? null : obj.getObject("referencedInteger").getInt("value"); }
@Test public void testEnumAndInlineClass() throws IOException { HollowObjectMapper mapper = new HollowObjectMapper(writeStateEngine); mapper.add(TestEnum.ONE); mapper.add(TestEnum.TWO); mapper.add(TestEnum.THREE); roundTripSnapshot(); HollowPrimaryKeyIndex idx = new HollowPrimaryKeyIndex(readStateEngine, new PrimaryKey("TestEnum", "_name")); int twoOrdinal = idx.getMatchingOrdinal("TWO"); GenericHollowObject obj = new GenericHollowObject(readStateEngine, "TestEnum", twoOrdinal); Assert.assertEquals("TWO", obj.getString("_name")); GenericHollowObject subObj = obj.getObject("testClass"); Assert.assertEquals(2, subObj.getInt("val1")); Assert.assertEquals(3, subObj.getInt("val2")); }