use of org.apache.geode.DataSerializer in project geode by apache.
the class DataSerializableJUnitTest method testRegistrationListeners.
/**
* Tests that <code>RegistrationListener</code>s are invoked at the proper times.
*/
@Test
public void testRegistrationListeners() {
final DataSerializer[] array = new DataSerializer[2];
TestRegistrationListener l1 = new TestRegistrationListener() {
@Override
public void newDataSerializer2(DataSerializer ds) {
array[0] = ds;
}
};
TestRegistrationListener l2 = new TestRegistrationListener() {
@Override
public void newDataSerializer2(DataSerializer ds) {
array[1] = ds;
}
};
InternalDataSerializer.addRegistrationListener(l1);
InternalDataSerializer.addRegistrationListener(l2);
byte id = (byte) 42;
try {
DataSerializer ds = DataSerializer.register(DS42.class);
assertTrue(l1.wasInvoked());
assertSame(ds, array[0]);
assertTrue(l2.wasInvoked());
assertSame(ds, array[1]);
} finally {
InternalDataSerializer.unregister(id);
InternalDataSerializer.removeRegistrationListener(l1);
InternalDataSerializer.removeRegistrationListener(l2);
}
Class c = DataSerializableImpl.class;
id = (byte) 100;
final Instantiator inst0 = new Instantiator(c, id) {
@Override
public DataSerializable newInstance() {
return new DataSerializableImpl();
}
};
TestRegistrationListener l3 = new TestRegistrationListener() {
@Override
public void newInstantiator2(Instantiator inst) {
assertEquals(inst0, inst);
}
};
TestRegistrationListener l4 = new TestRegistrationListener() {
@Override
public void newInstantiator2(Instantiator inst) {
assertEquals(inst0, inst);
}
};
InternalDataSerializer.addRegistrationListener(l3);
InternalDataSerializer.addRegistrationListener(l4);
try {
Instantiator.register(inst0);
assertTrue(l3.wasInvoked());
assertTrue(l4.wasInvoked());
} finally {
InternalInstantiator.unregister(c, id);
InternalDataSerializer.removeRegistrationListener(l3);
InternalDataSerializer.removeRegistrationListener(l4);
}
}
use of org.apache.geode.DataSerializer in project geode by apache.
the class DataSerializableJUnitTest method testRegisterTwoSerializers.
/**
* Tests that registering two <code>Serializer</code>s with the same id throws an exception.
*/
@Test
public void testRegisterTwoSerializers() {
byte id = (byte) 42;
DataSerializer.register(DS42.class);
DataSerializer serializer2 = new DS42() {
};
try {
DataSerializer.register(serializer2.getClass());
fail("Should have thrown an IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// pass...
} finally {
InternalDataSerializer.unregister(id);
}
}
use of org.apache.geode.DataSerializer in project geode by apache.
the class DataSerializableJUnitTest method testUDDS2.
/**
* Make sure a user defined ds with an id of 2 bytes works.
*/
@Test
public void testUDDS2() throws Exception {
DataSerializer ds2 = DataSerializer.register(Class_testSupportedClasses3.class);
int id2 = ds2.getId();
try {
Object o = new NonDataSerializable(new Random());
DataSerializer.writeObject(o, getDataOutput());
assertTrue(Class_testSupportedClasses3.wasInvoked);
assertTrue(Class_testSupportedClasses3.toDataInvoked);
assertFalse(Class_testSupportedClasses3.fromDataInvoked);
Object o2 = DataSerializer.readObject(getDataInput());
assertTrue(Class_testSupportedClasses3.fromDataInvoked);
assertEquals(o, o2);
} finally {
InternalDataSerializer.unregister(id2);
}
}
use of org.apache.geode.DataSerializer in project geode by apache.
the class DSObjectLocalOnly method verifyDataSerializers.
public static void verifyDataSerializers(final int numOfDataSerializers, final boolean allowNonLocal) {
WaitCriterion wc = new StoppableWaitCriterion() {
String excuse;
private DataSerializer[] getSerializers() {
allowNonLocalTL.set(allowNonLocal);
try {
return InternalDataSerializer.getSerializers();
} finally {
allowNonLocalTL.remove();
}
}
public boolean done() {
return getSerializers().length == numOfDataSerializers;
}
public String description() {
return "expected " + numOfDataSerializers + " but got this " + InternalDataSerializer.getSerializers().length + " serializers=" + java.util.Arrays.toString(getSerializers());
}
public boolean stopWaiting() {
return getSerializers().length > numOfDataSerializers;
}
};
Wait.waitForCriterion(wc, 60 * 1000, 1000, true);
}
use of org.apache.geode.DataSerializer in project geode by apache.
the class DiskInitFile method cmnDataSerializerId.
public void cmnDataSerializerId(Class dsc) {
if (dsc != null) {
DataSerializer ds = InternalDataSerializer.register(dsc, /* dsId, */
true);
this.dsIds.add(ds.getId());
}
this.ifLiveRecordCount++;
this.ifTotalRecordCount++;
}
Aggregations