@Test public void addField() { long longValue = random.nextLong(); double doubleValue = random.nextDouble(); TestClassLongDouble object = new TestClassLongDouble(); object.longField = longValue; object.doubleField = doubleValue; Mockito.when(classSchema.getFieldMarker("longField")).thenReturn(Integer.valueOf(1)); Mockito.when(classSchema.getFieldMarker("doubleField")).thenReturn(Integer.valueOf(2)); Kryo kryo = new Kryo(); kryo.register(TestClassLongDouble.class, new CustomCompatibleFieldSerializer<TestClassLongDouble>(kryo, TestClassLongDouble.class, classSchemaManager)); Output output = new Output(1024); kryo.writeClassAndObject(output, object); Mockito.when(classSchema.getFieldMarker("floatField")).thenReturn(Integer.valueOf(3)); kryo = new Kryo(); kryo.register(TestClassLongDoubleFloat.class, new CustomCompatibleFieldSerializer<TestClassLongDoubleFloat>(kryo, TestClassLongDoubleFloat.class, classSchemaManager)); Input input = new Input(output.getBuffer()); Object deserialized = kryo.readClassAndObject(input); assertThat(deserialized, is(instanceOf(TestClassLongDoubleFloat.class))); TestClassLongDoubleFloat deserializedTestClass = (TestClassLongDoubleFloat) deserialized; assertThat(deserializedTestClass.longField, is(equalTo(longValue))); assertThat(deserializedTestClass.doubleField, is(equalTo(doubleValue))); assertThat(deserializedTestClass.floatField, is(equalTo(0F))); }
@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 addAndRemoveFields() { long longValue = random.nextLong(); double doubleValue = random.nextDouble(); TestClassLongDouble object = new TestClassLongDouble(); object.longField = longValue; object.doubleField = doubleValue; Mockito.when(classSchema.getFieldMarker("longField")).thenReturn(Integer.valueOf(1)); Mockito.when(classSchema.getFieldMarker("doubleField")).thenReturn(Integer.valueOf(2)); Kryo kryo = new Kryo(); kryo.register(TestClassLongDouble.class, new CustomCompatibleFieldSerializer<TestClassLongDouble>(kryo, TestClassLongDouble.class, classSchemaManager)); Output output = new Output(1024); kryo.writeClassAndObject(output, object); Mockito.when(classSchema.getFieldMarker("floatField")).thenReturn(3); kryo = new Kryo(); kryo.register(TestClassDoubleFloat.class, new CustomCompatibleFieldSerializer<TestClassDoubleFloat>(kryo, TestClassDoubleFloat.class, classSchemaManager)); Input input = new Input(output.getBuffer()); Object deserialized = kryo.readClassAndObject(input); assertThat(deserialized, is(instanceOf(TestClassDoubleFloat.class))); TestClassDoubleFloat deserializedTestClass = (TestClassDoubleFloat) deserialized; assertThat(deserializedTestClass.doubleField, is(equalTo(doubleValue))); assertThat(deserializedTestClass.floatField, is(equalTo(0F))); }
@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))); }
kryo.register(PlatformIdent.class, new CustomCompatibleFieldSerializer<PlatformIdent>(kryo, PlatformIdent.class, schemaManager)); kryo.register(MethodIdent.class, new CustomCompatibleFieldSerializer<MethodIdent>(kryo, MethodIdent.class, schemaManager)); kryo.register(SensorTypeIdent.class, new CustomCompatibleFieldSerializer<SensorTypeIdent>(kryo, SensorTypeIdent.class, schemaManager)); kryo.register(MethodSensorTypeIdent.class, new CustomCompatibleFieldSerializer<MethodSensorTypeIdent>(kryo, MethodSensorTypeIdent.class, schemaManager)); kryo.register(PlatformSensorTypeIdent.class, new CustomCompatibleFieldSerializer<PlatformSensorTypeIdent>(kryo, PlatformSensorTypeIdent.class, schemaManager, true)); kryo.register(ExceptionSensorData.class, new InvocationAwareDataSerializer<ExceptionSensorData>(kryo, ExceptionSensorData.class, schemaManager)); kryo.register(ExceptionEvent.class, new EnumSerializer(ExceptionEvent.class)); kryo.register(ParameterContentData.class, new CustomCompatibleFieldSerializer<ParameterContentData>(kryo, ParameterContentData.class, schemaManager)); kryo.register(MemoryInformationData.class, new CustomCompatibleFieldSerializer<MemoryInformationData>(kryo, MemoryInformationData.class, schemaManager)); kryo.register(CpuInformationData.class, new CustomCompatibleFieldSerializer<CpuInformationData>(kryo, CpuInformationData.class, schemaManager)); kryo.register(SystemInformationData.class, new CustomCompatibleFieldSerializer<SystemInformationData>(kryo, SystemInformationData.class, schemaManager)); kryo.register(VmArgumentData.class, new CustomCompatibleFieldSerializer<VmArgumentData>(kryo, VmArgumentData.class, schemaManager)); kryo.register(ThreadInformationData.class, new CustomCompatibleFieldSerializer<ThreadInformationData>(kryo, ThreadInformationData.class, schemaManager)); kryo.register(RuntimeInformationData.class, new CustomCompatibleFieldSerializer<RuntimeInformationData>(kryo, RuntimeInformationData.class, schemaManager)); kryo.register(CompilationInformationData.class, new CustomCompatibleFieldSerializer<CompilationInformationData>(kryo, CompilationInformationData.class, schemaManager)); kryo.register(ClassLoadingInformationData.class, new CustomCompatibleFieldSerializer<ClassLoadingInformationData>(kryo, ClassLoadingInformationData.class, schemaManager)); kryo.register(ParameterContentType.class, new EnumSerializer(ParameterContentType.class)); kryo.register(MethodIdentToSensorType.class, new CustomCompatibleFieldSerializer<MethodIdentToSensorType>(kryo, MethodIdentToSensorType.class, schemaManager)); kryo.register(TimeFrame.class, new CustomCompatibleFieldSerializer<TimeFrame>(kryo, TimeFrame.class, schemaManager), nextRegistrationId++); kryo.register(JmxSensorTypeIdent.class, new CustomCompatibleFieldSerializer<JmxSensorTypeIdent>(kryo, JmxSensorTypeIdent.class, schemaManager, true), nextRegistrationId++); kryo.register(JmxDefinitionDataIdent.class, new CustomCompatibleFieldSerializer<JmxDefinitionDataIdent>(kryo, JmxDefinitionDataIdent.class, schemaManager), nextRegistrationId++); kryo.register(JmxSensorValueData.class, new CustomCompatibleFieldSerializer<JmxSensorValueData>(kryo, JmxSensorValueData.class, schemaManager), nextRegistrationId++); kryo.register(HttpInfo.class, new CustomCompatibleFieldSerializer<HttpInfo>(kryo, HttpInfo.class, schemaManager), nextRegistrationId++);
kryo.register(StorageBranch.class, new CustomCompatibleFieldSerializer<StorageBranch<?>>(kryo, StorageBranch.class, schemaManager), nextRegistrationId++); kryo.register(StorageBranchIndexer.class, new CustomCompatibleFieldSerializer<StorageBranchIndexer<?>>(kryo, StorageBranchIndexer.class, schemaManager), nextRegistrationId++); kryo.register(SimpleStorageDescriptor.class, new CustomCompatibleFieldSerializer<SimpleStorageDescriptor>(kryo, SimpleStorageDescriptor.class, schemaManager), nextRegistrationId++); CustomCompatibleFieldSerializer<ArrayBasedStorageLeaf<?>> leafSerializer = new CustomCompatibleFieldSerializer<>(kryo, ArrayBasedStorageLeaf.class, schemaManager); leafSerializer.setCopyTransient(false); kryo.register(ArrayBasedStorageLeaf.class, leafSerializer, nextRegistrationId++); kryo.register(LeafWithNoDescriptors.class, new CustomCompatibleFieldSerializer<LeafWithNoDescriptors<?>>(kryo, LeafWithNoDescriptors.class, schemaManager), nextRegistrationId++); kryo.register(StorageData.class, new CustomCompatibleFieldSerializer<StorageData>(kryo, StorageData.class, schemaManager), nextRegistrationId++); kryo.register(LocalStorageData.class, new CustomCompatibleFieldSerializer<LocalStorageData>(kryo, LocalStorageData.class, schemaManager), nextRegistrationId++); kryo.register(StorageState.class, new EnumSerializer(StorageState.class)); kryo.register(BooleanStorageLabel.class, new CustomCompatibleFieldSerializer<BooleanStorageLabel>(kryo, BooleanStorageLabel.class, schemaManager), nextRegistrationId++); kryo.register(DateStorageLabel.class, new CustomCompatibleFieldSerializer<DateStorageLabel>(kryo, DateStorageLabel.class, schemaManager), nextRegistrationId++); kryo.register(NumberStorageLabel.class, new CustomCompatibleFieldSerializer<NumberStorageLabel>(kryo, NumberStorageLabel.class, schemaManager), nextRegistrationId++); kryo.register(StringStorageLabel.class, new CustomCompatibleFieldSerializer<StringStorageLabel>(kryo, StringStorageLabel.class, schemaManager), nextRegistrationId++); kryo.register(AssigneeLabelType.class, new CustomCompatibleFieldSerializer<AssigneeLabelType>(kryo, AssigneeLabelType.class, schemaManager, true), nextRegistrationId++); kryo.register(CreationDateLabelType.class, new CustomCompatibleFieldSerializer<CreationDateLabelType>(kryo, CreationDateLabelType.class, schemaManager, true), nextRegistrationId++); kryo.register(CustomBooleanLabelType.class, new CustomCompatibleFieldSerializer<CustomBooleanLabelType>(kryo, CustomBooleanLabelType.class, schemaManager, true), nextRegistrationId++); kryo.register(CustomDateLabelType.class, new CustomCompatibleFieldSerializer<CustomDateLabelType>(kryo, CustomDateLabelType.class, schemaManager, true), nextRegistrationId++); kryo.register(CustomNumberLabelType.class, new CustomCompatibleFieldSerializer<CustomNumberLabelType>(kryo, CustomNumberLabelType.class, schemaManager, true), nextRegistrationId++); kryo.register(CustomStringLabelType.class, new CustomCompatibleFieldSerializer<CustomStringLabelType>(kryo, CustomStringLabelType.class, schemaManager, true), nextRegistrationId++); kryo.register(ExploredByLabelType.class, new CustomCompatibleFieldSerializer<ExploredByLabelType>(kryo, ExploredByLabelType.class, schemaManager, true), nextRegistrationId++); kryo.register(RatingLabelType.class, new CustomCompatibleFieldSerializer<RatingLabelType>(kryo, RatingLabelType.class, schemaManager, true), nextRegistrationId++); kryo.register(StatusLabelType.class, new CustomCompatibleFieldSerializer<StatusLabelType>(kryo, StatusLabelType.class, schemaManager, true), nextRegistrationId++); kryo.register(UseCaseLabelType.class, new CustomCompatibleFieldSerializer<UseCaseLabelType>(kryo, UseCaseLabelType.class, schemaManager, true), nextRegistrationId++); kryo.register(MethodIdentIndexer.class, new FieldSerializer<MethodIdentIndexer<?>>(kryo, MethodIdentIndexer.class), nextRegistrationId++);