protected void testEquals(boolean ascending) { try { // Just setup two identical output/inputViews and go over their data to see if compare works TestOutputView out1; TestOutputView out2; TestInputView in1; TestInputView in2; // Now use comparator and compare TypeComparator<T> comparator = getComparator(ascending); T[] data = getSortedData(); for (T d : data) { out2 = new TestOutputView(); writeSortedData(d, out2); in2 = out2.getInputView(); out1 = new TestOutputView(); writeSortedData(d, out1); in1 = out1.getInputView(); assertTrue(comparator.compareSerialized(in1, in2) == 0); } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Exception in test: " + e.getMessage()); } }
@Test public void testNormalizedKeyReadWriter() { try { T[] data = getSortedData(); T reuse = getSortedData()[0]; TypeComparator<T> comp1 = getComparator(true); if(!comp1.supportsSerializationWithKeyNormalization()){ return; } TypeComparator<T> comp2 = comp1.duplicate(); comp2.setReference(reuse); TestOutputView out = new TestOutputView(); TestInputView in; for (T value : data) { comp1.setReference(value); comp1.writeWithKeyNormalization(value, out); in = out.getInputView(); comp1.readWithKeyDenormalization(reuse, in); assertTrue(comp1.compareToReference(comp2) == 0); } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Exception in test: " + e.getMessage()); } }
out1 = new TestOutputView(); writeSortedData(data[x], out1); in1 = out1.getInputView(); out2 = new TestOutputView(); writeSortedData(data[y], out2); in2 = out2.getInputView();
private void testWriteAndReadConfigSnapshot(Coder<String> coder) throws IOException { CoderTypeSerializer<String> serializer = new CoderTypeSerializer<>(coder); TypeSerializerConfigSnapshot writtenSnapshot = serializer.snapshotConfiguration(); ComparatorTestBase.TestOutputView outView = new ComparatorTestBase.TestOutputView(); writtenSnapshot.write(outView); TypeSerializerConfigSnapshot readSnapshot = new CoderTypeSerializerConfigSnapshot<>(); readSnapshot.read(outView.getInputView()); assertThat(readSnapshot, is(writtenSnapshot)); } }
private void testWriteAndReadConfigSnapshot(Coder<String> coder) throws IOException { CoderTypeSerializer<String> serializer = new CoderTypeSerializer<>(coder); TypeSerializerConfigSnapshot writtenSnapshot = serializer.snapshotConfiguration(); ComparatorTestBase.TestOutputView outView = new ComparatorTestBase.TestOutputView(); writtenSnapshot.write(outView); TypeSerializerConfigSnapshot readSnapshot = new CoderTypeSerializerConfigSnapshot<>(); readSnapshot.read(outView.getInputView()); assertThat(readSnapshot, is(writtenSnapshot)); } }
private void testWriteAndReadConfigSnapshot(Coder<String> coder) throws IOException { CoderTypeSerializer<String> serializer = new CoderTypeSerializer<>(coder); TypeSerializerConfigSnapshot writtenSnapshot = serializer.snapshotConfiguration(); ComparatorTestBase.TestOutputView outView = new ComparatorTestBase.TestOutputView(); writtenSnapshot.write(outView); TypeSerializerConfigSnapshot readSnapshot = new CoderTypeSerializerConfigSnapshot<>(); readSnapshot.read(outView.getInputView()); assertThat(readSnapshot, is(writtenSnapshot)); } }
@Test public void testSerializeIndividually() throws IOException { EitherTypeInfo<LongValue, DoubleValue> eitherTypeInfo = new EitherTypeInfo<>( ValueTypeInfo.LONG_VALUE_TYPE_INFO, ValueTypeInfo.DOUBLE_VALUE_TYPE_INFO); EitherSerializer<LongValue, DoubleValue> eitherSerializer = (EitherSerializer<LongValue, DoubleValue>) eitherTypeInfo.createSerializer(new ExecutionConfig()); LongValue lv = new LongValue(); DoubleValue dv = new DoubleValue(); Either<LongValue, DoubleValue> left = Left(lv); Either<LongValue, DoubleValue> right = Right(dv); TestOutputView out = new TestOutputView(); eitherSerializer.serialize(left, out); eitherSerializer.serialize(right, out); eitherSerializer.serialize(left, out); TestInputView in = out.getInputView(); // the first deserialization creates a new instance of Left Either<LongValue, DoubleValue> copy0 = eitherSerializer.deserialize(right, in); // then the cross-references are used for future copies Either<LongValue, DoubleValue> copy1 = eitherSerializer.deserialize(copy0, in); Either<LongValue, DoubleValue> copy2 = eitherSerializer.deserialize(copy1, in); // validate reference equality assertSame(right, copy1); assertSame(copy0, copy2); // validate reference equality of contained objects assertSame(right.right(), copy1.right()); assertSame(copy0.left(), copy2.left()); }