use of org.apache.geode.Instantiator in project geode by apache.
the class DataSerializableJUnitTest method testInstantiator2.
@Test
public void testInstantiator2() throws Exception {
final boolean[] wasInvoked = new boolean[] { false };
Instantiator.register(new Instantiator(DataSerializableImpl.class, 20000) {
public DataSerializable newInstance() {
wasInvoked[0] = true;
return new DataSerializableImpl();
}
});
try {
byte id = (byte) 57;
Class_testInstantiator.supClass = DataSerializableImpl.class;
DataSerializer.register(Class_testInstantiator.class);
try {
Object o = new DataSerializableImpl(new Random());
DataSerializer.writeObject(o, getDataOutput());
Object o2 = DataSerializer.readObject(getDataInput());
assertTrue(wasInvoked[0]);
assertEquals(o, o2);
} finally {
InternalDataSerializer.unregister(id);
}
} finally {
InternalInstantiator.unregister(DataSerializableImpl.class, 20000);
}
}
use of org.apache.geode.Instantiator in project geode by apache.
the class DataSerializableJUnitTest method testInstantiator4.
@Test
public void testInstantiator4() throws Exception {
final boolean[] wasInvoked = new boolean[] { false };
Instantiator.register(new Instantiator(DataSerializableImpl.class, 123456789) {
public DataSerializable newInstance() {
wasInvoked[0] = true;
return new DataSerializableImpl();
}
});
try {
byte id = (byte) 57;
Class_testInstantiator.supClass = DataSerializableImpl.class;
DataSerializer.register(Class_testInstantiator.class);
try {
Object o = new DataSerializableImpl(new Random());
DataSerializer.writeObject(o, getDataOutput());
Object o2 = DataSerializer.readObject(getDataInput());
assertTrue(wasInvoked[0]);
assertEquals(o, o2);
} finally {
InternalDataSerializer.unregister(id);
}
} finally {
InternalInstantiator.unregister(DataSerializableImpl.class, 123456789);
}
}
use of org.apache.geode.Instantiator in project geode by apache.
the class DataTypeJUnitTest method getDataTypeShouldReturnUserDataSeriazliable4.
@Test
public void getDataTypeShouldReturnUserDataSeriazliable4() throws IOException {
Instantiator mockInstantiator = PowerMockito.mock(Instantiator.class);
doReturn(CustId.class).when(mockInstantiator).getInstantiatedClass();
mockInstantiator.getInstantiatedClass();
int someClassId = 1;
PowerMockito.mockStatic(InternalInstantiator.class);
when(InternalInstantiator.getClassId(mockInstantiator.getClass())).thenReturn(someClassId);
when(InternalInstantiator.getInstantiator(someClassId)).thenReturn(mockInstantiator);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(baos);
out.writeByte(DSCODE.USER_DATA_SERIALIZABLE_4);
out.writeInt(someClassId);
byte[] bytes = baos.toByteArray();
String type = DataType.getDataType(bytes);
assertThat(type).isEqualTo("org.apache.geode.Instantiator:org.apache.geode.internal.cache.execute.data.CustId");
}
use of org.apache.geode.Instantiator in project geode by apache.
the class DataSerializableJUnitTest method testInstantiator.
/**
* Tests that an <code>Instantiator</code> is invoked at the appropriate times.
*/
@Test
public void testInstantiator() throws Exception {
final boolean[] wasInvoked = new boolean[] { false };
Instantiator.register(new Instantiator(DataSerializableImpl.class, (byte) 45) {
public DataSerializable newInstance() {
wasInvoked[0] = true;
return new DataSerializableImpl();
}
});
try {
byte id = (byte) 57;
Class_testInstantiator.supClass = DataSerializableImpl.class;
DataSerializer.register(Class_testInstantiator.class);
try {
Object o = new DataSerializableImpl(new Random());
DataSerializer.writeObject(o, getDataOutput());
Object o2 = DataSerializer.readObject(getDataInput());
assertTrue(wasInvoked[0]);
assertEquals(o, o2);
} finally {
InternalDataSerializer.unregister(id);
}
} finally {
InternalInstantiator.unregister(DataSerializableImpl.class, (byte) 45);
}
}
Aggregations