@Test public void allFields() { long longValue = random.nextLong(); double doubleValue = random.nextDouble(); float floatValue = random.nextFloat(); TestClassLongDoubleFloat object = new TestClassLongDoubleFloat(); object.longField = longValue; object.doubleField = doubleValue; object.floatField = floatValue; Mockito.when(classSchema.getFieldMarker("longField")).thenReturn(Integer.valueOf(1)); Mockito.when(classSchema.getFieldMarker("doubleField")).thenReturn(Integer.valueOf(2)); Mockito.when(classSchema.getFieldMarker("floatField")).thenReturn(Integer.valueOf(3)); Kryo kryo = new Kryo(); kryo.register(TestClassLongDoubleFloat.class, new CustomCompatibleFieldSerializer<TestClassLongDoubleFloat>(kryo, TestClassLongDoubleFloat.class, classSchemaManager)); Output output = new Output(1024); kryo.writeClassAndObject(output, object); Input input = new Input(output.getBuffer()); Object deserialized = kryo.readClassAndObject(input); Assert.assertTrue(deserialized instanceof TestClassLongDoubleFloat); TestClassLongDoubleFloat deserializedTestClass = (TestClassLongDoubleFloat) deserialized; assertThat(deserializedTestClass.longField, is(equalTo(longValue))); assertThat(deserializedTestClass.doubleField, is(equalTo(doubleValue))); assertThat(deserializedTestClass.floatField, is(equalTo(floatValue))); }
@Test public void removeField() { long longValue = random.nextLong(); double doubleValue = random.nextDouble(); float floatValue = random.nextFloat(); TestClassLongDoubleFloat object = new TestClassLongDoubleFloat(); object.longField = longValue; object.doubleField = doubleValue; object.floatField = floatValue; Mockito.when(classSchema.getFieldMarker("longField")).thenReturn(Integer.valueOf(1)); Mockito.when(classSchema.getFieldMarker("doubleField")).thenReturn(Integer.valueOf(2)); Mockito.when(classSchema.getFieldMarker("floatField")).thenReturn(Integer.valueOf(3)); Kryo kryo = new Kryo(); kryo.register(TestClassLongDoubleFloat.class, new CustomCompatibleFieldSerializer<TestClassLongDoubleFloat>(kryo, TestClassLongDoubleFloat.class, classSchemaManager)); Output output = new Output(1024); kryo.writeClassAndObject(output, object); kryo = new Kryo(); kryo.register(TestClassLongDouble.class, new CustomCompatibleFieldSerializer<TestClassLongDouble>(kryo, TestClassLongDouble.class, classSchemaManager)); Input input = new Input(output.getBuffer()); Object deserialized = kryo.readClassAndObject(input); assertThat(deserialized, is(instanceOf(TestClassLongDouble.class))); TestClassLongDouble deserializedTestClass = (TestClassLongDouble) deserialized; assertThat(deserializedTestClass.longField, is(equalTo(longValue))); assertThat(deserializedTestClass.doubleField, is(equalTo(doubleValue))); }
@Test public void zeroField() { long longValue = random.nextLong(); double doubleValue = random.nextDouble(); float floatValue = random.nextFloat(); TestClassLongDoubleFloat object = new TestClassLongDoubleFloat(); object.longField = longValue; object.doubleField = doubleValue; object.floatField = floatValue; Mockito.when(classSchema.getFieldMarker("longField")).thenReturn(null); Mockito.when(classSchema.getFieldMarker("doubleField")).thenReturn(null); Mockito.when(classSchema.getFieldMarker("floatField")).thenReturn(null); Kryo kryo = new Kryo(); kryo.register(TestClassLongDoubleFloat.class, new CustomCompatibleFieldSerializer<TestClassLongDoubleFloat>(kryo, TestClassLongDoubleFloat.class, classSchemaManager)); Output output = new Output(1024); kryo.writeClassAndObject(output, object); Input input = new Input(output.getBuffer()); Object deserialized = kryo.readClassAndObject(input); Assert.assertTrue(deserialized instanceof TestClassLongDoubleFloat); TestClassLongDoubleFloat deserializedTestClass = (TestClassLongDoubleFloat) deserialized; assertThat(deserializedTestClass.longField, is(equalTo(0L))); assertThat(deserializedTestClass.doubleField, is(equalTo(0D))); assertThat(deserializedTestClass.floatField, is(equalTo(0F))); }