ColumnIO { @Override public String toString() { return this.getClass().getSimpleName()+" "+type.getName() +" r:"+repetitionLevel +" d:"+definitionLevel +" "+Arrays.toString(fieldPath); } ColumnIO(Type type, GroupColumnIO parent, int index); String getFieldPath(int level); int[] getIndexFieldPath(); int getIndexFieldPath(int level); int getIndex(); String getName(); Type getType(); GroupColumnIO getParent(); @Override String toString();  }
@Test public void testSchema() { assertEquals(schemaString, schema.toString()); }
@Test public void testGroupWriter() { List<Group> result = new ArrayList<Group>(); GroupRecordConsumer groupConsumer = new GroupRecordConsumer(new SimpleGroupFactory(schema)); GroupWriter groupWriter = new GroupWriter(new RecordConsumerLoggingWrapper(groupConsumer), schema); groupWriter.write(r1); result.add(groupConsumer.getCurrentRecord()); groupWriter.write(r2); result.add(groupConsumer.getCurrentRecord()); assertEquals("deserialization does not display the expected result", result.get(0).toString(), r1.toString()); assertEquals("deserialization does not display the expected result", result.get(1).toString(), r2.toString()); }
@Test public void testWriteWithGroupWriter() { final String[] expected = { "[DocId]: 10, r:0, d:0", "[Links, Backward]: null, r:0, d:1", "[Links, Forward]: 20, r:0, d:2", "[Links, Forward]: 40, r:1, d:2", "[Links, Forward]: 60, r:1, d:2", "[Name, Language, Code]: en-us, r:0, d:2", "[Name, Language, Country]: us, r:0, d:3", "[Name, Language, Code]: en, r:2, d:2", "[Name, Language, Country]: null, r:2, d:2", "[Name, Url]: http: "[Name, Language, Code]: null, r:1, d:1", "[Name, Language, Country]: null, r:1, d:1", "[Name, Url]: http: "[Name, Language, Code]: en-gb, r:1, d:2", "[Name, Language, Country]: gb, r:1, d:3", "[Name, Url]: null, r:1, d:1", "[DocId]: 20, r:0, d:0", "[Links, Backward]: 10, r:0, d:2", "[Links, Backward]: 30, r:1, d:2", "[Links, Forward]: 80, r:0, d:2", "[Name, Language, Code]: null, r:0, d:1", "[Name, Language, Country]: null, r:0, d:1", "[Name, Url]: http: }; ColumnWriteStore columns = new ColumnWriteStore() { int counter = 0; @Override public ColumnWriter getColumnWriter(final ColumnDescriptor path) { return new ColumnWriter() { private void validate(Object value, int repetitionLevel, int definitionLevel) { String actual = Arrays.toString(path.getPath())+": "+value+", r:"+repetitionLevel+", d:"+definitionLevel; assertEquals("event #" + counter, expected[counter], actual); ++ counter; } @Override public void writeNull(int repetitionLevel, int definitionLevel) { validate(null, repetitionLevel, definitionLevel); } @Override public void write(Binary value, int repetitionLevel, int definitionLevel) { validate(value.toStringUsingUTF8(), repetitionLevel, definitionLevel); } @Override public void write(boolean value, int repetitionLevel, int definitionLevel) { validate(value, repetitionLevel, definitionLevel); } @Override public void write(int value, int repetitionLevel, int definitionLevel) { validate(value, repetitionLevel, definitionLevel); } @Override public void write(long value, int repetitionLevel, int definitionLevel) { validate(value, repetitionLevel, definitionLevel); } @Override public void write(float value, int repetitionLevel, int definitionLevel) { validate(value, repetitionLevel, definitionLevel); } @Override public void write(double value, int repetitionLevel, int definitionLevel) { validate(value, repetitionLevel, definitionLevel); } @Override public void flush() { throw new UnsupportedOperationException(); } @Override public long getBufferedSizeInMemory() { throw new UnsupportedOperationException(); } }; } @Override public void flush() { assertEquals("read all events", expected.length, counter); } }; MessageColumnIO columnIO = new ColumnIOFactory().getColumnIO(schema); GroupWriter groupWriter = new GroupWriter(columnIO.getRecordWriter(columns), schema); groupWriter.write(r1); groupWriter.write(r2); columns.flush(); }