use of org.apache.geode.pdx.internal.PdxInstanceImpl in project geode by apache.
the class PdxRenameDUnitTest method testPdxRenameVersioning.
@Test
public void testPdxRenameVersioning() throws Exception {
final String DS_NAME = "PdxRenameDUnitTestDiskStore";
final String DS_NAME2 = "PdxRenameDUnitTestDiskStore2";
final int[] locatorPorts = AvailablePortHelper.getRandomAvailableTCPPorts(2);
final File f = new File(DS_NAME);
f.mkdir();
final File f2 = new File(DS_NAME2);
f2.mkdir();
this.filesToBeDeleted.add(DS_NAME);
this.filesToBeDeleted.add(DS_NAME2);
final Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "localhost[" + locatorPorts[0] + "],localhost[" + locatorPorts[1] + "]");
props.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
Host host = Host.getHost(0);
VM vm1 = host.getVM(0);
VM vm2 = host.getVM(1);
vm1.invoke(new SerializableCallable() {
public Object call() throws Exception {
disconnectFromDS();
props.setProperty(START_LOCATOR, "localhost[" + locatorPorts[0] + "]");
final Cache cache = (new CacheFactory(props)).setPdxPersistent(true).setPdxDiskStore(DS_NAME).create();
DiskStoreFactory dsf = cache.createDiskStoreFactory();
dsf.setDiskDirs(new File[] { f });
dsf.create(DS_NAME);
RegionFactory<String, PdxValue> rf1 = cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT);
rf1.setDiskStoreName(DS_NAME);
Region<String, PdxValue> region1 = rf1.create("region1");
region1.put("key1", new PdxValue(1));
return null;
}
});
vm2.invoke(new SerializableCallable() {
public Object call() throws Exception {
disconnectFromDS();
props.setProperty(START_LOCATOR, "localhost[" + locatorPorts[1] + "]");
final Cache cache = (new CacheFactory(props)).setPdxReadSerialized(true).setPdxPersistent(true).setPdxDiskStore(DS_NAME2).create();
DiskStoreFactory dsf = cache.createDiskStoreFactory();
dsf.setDiskDirs(new File[] { f2 });
dsf.create(DS_NAME2);
RegionFactory rf1 = cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT);
rf1.setDiskStoreName(DS_NAME2);
Region region1 = rf1.create("region1");
Object v = region1.get("key1");
assertNotNull(v);
cache.close();
return null;
}
});
vm1.invoke(new SerializableCallable() {
public Object call() throws Exception {
Cache cache = CacheFactory.getAnyInstance();
if (cache != null && !cache.isClosed()) {
cache.close();
}
return null;
}
});
vm1.invoke(new SerializableCallable() {
public Object call() throws Exception {
Collection<Object> renameResults = DiskStoreImpl.pdxRename(DS_NAME, new File[] { f }, "apache", "pivotal");
assertEquals(2, renameResults.size());
for (Object o : renameResults) {
if (o instanceof PdxType) {
PdxType t = (PdxType) o;
assertEquals("org.pivotal.geode.internal.PdxRenameDUnitTest$PdxValue", t.getClassName());
} else {
EnumInfo ei = (EnumInfo) o;
assertEquals("org.pivotal.geode.internal.PdxRenameDUnitTest$Day", ei.getClassName());
}
}
return null;
}
});
vm1.invoke(new SerializableCallable() {
public Object call() throws Exception {
props.setProperty(START_LOCATOR, "localhost[" + locatorPorts[0] + "]");
final Cache cache = (new CacheFactory(props)).setPdxPersistent(true).setPdxDiskStore(DS_NAME).create();
DiskStoreFactory dsf = cache.createDiskStoreFactory();
dsf.setDiskDirs(new File[] { f });
dsf.create(DS_NAME);
RegionFactory<String, PdxValue> rf1 = cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT);
rf1.setDiskStoreName(DS_NAME);
Region<String, PdxValue> region1 = rf1.create("region1");
return null;
}
});
vm2.invoke(new SerializableCallable() {
public Object call() throws Exception {
disconnectFromDS();
props.setProperty(START_LOCATOR, "localhost[" + locatorPorts[1] + "]");
final Cache cache = (new CacheFactory(props)).setPdxReadSerialized(true).setPdxPersistent(true).setPdxDiskStore(DS_NAME2).create();
DiskStoreFactory dsf = cache.createDiskStoreFactory();
dsf.setDiskDirs(new File[] { f2 });
dsf.create(DS_NAME2);
RegionFactory rf1 = cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT);
rf1.setDiskStoreName(DS_NAME2);
Region region1 = rf1.create("region1");
PdxInstance v = (PdxInstance) region1.get("key1");
assertNotNull(v);
assertEquals("org.pivotal.geode.internal.PdxRenameDUnitTest$PdxValue", ((PdxInstanceImpl) v).getClassName());
cache.close();
return null;
}
});
vm1.invoke(new SerializableCallable() {
public Object call() throws Exception {
Cache cache = CacheFactory.getAnyInstance();
if (cache != null && !cache.isClosed()) {
cache.close();
}
return null;
}
});
}
use of org.apache.geode.pdx.internal.PdxInstanceImpl in project geode by apache.
the class PdxStringJUnitTest method testHashCodeEquals.
@Test
public void testHashCodeEquals() throws Exception {
PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
pf.writeString("secId", "abc");
PdxInstanceImpl pi = (PdxInstanceImpl) pf.create();
PdxString pdx1 = (PdxString) pi.getRawField("secId");
Map<PdxString, String> map = new HashMap<PdxString, String>();
map.put(pdx1, "abc");
PdxString pdx2 = new PdxString("abc");
assertEquals(map.get(pdx2), "abc");
map = new Object2ObjectOpenHashMap();
map.put(pdx1, "abc");
assertEquals(map.get(pdx2), "abc");
}
use of org.apache.geode.pdx.internal.PdxInstanceImpl in project geode by apache.
the class PdxStringJUnitTest method testEquals.
@Test
public void testEquals() throws Exception {
PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
pf.writeString("secId", "abc");
PdxInstanceImpl pi = (PdxInstanceImpl) pf.create();
PdxString pdx1 = (PdxString) pi.getRawField("secId");
assertEquals(false, pdx1.equals(null));
assertEquals(false, pdx1.equals(new Date(37)));
PdxString pdx2 = new PdxString("abc");
assertEquals(pdx1, pdx2);
pdx2 = new PdxString("ABC");
assertEquals(false, pdx1.equals(pdx2));
}
use of org.apache.geode.pdx.internal.PdxInstanceImpl in project geode by apache.
the class CompiledOperation method eval0.
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "RV_RETURN_VALUE_OF_PUTIFABSENT_IGNORED", justification = "Does not matter if the methodDispatch that isn't stored in the map is used")
private Object eval0(Object receiver, Class resolutionType, ExecutionContext context) throws TypeMismatchException, FunctionDomainException, NameResolutionException, QueryInvocationTargetException {
if (receiver == null || receiver == QueryService.UNDEFINED)
return QueryService.UNDEFINED;
List args = new ArrayList();
List argTypes = new ArrayList();
Iterator i = this.args.iterator();
while (i.hasNext()) {
CompiledValue arg = (CompiledValue) i.next();
Object o = arg.evaluate(context);
// undefined arg produces undefines method result
if (o == QueryService.UNDEFINED)
return QueryService.UNDEFINED;
args.add(o);
// pass in null for the type if the runtime value is null
if (o == null)
argTypes.add(null);
else
// commented out because we currently always use the runtime type for args
// else if (arg.getType() == Identifier)
// {
// CompiledValue resolved = context.resolve(((CompiledID)arg).getId());
// if (resolved != null && resolved.getType() == ITERATOR)
// argTypes.add(((RuntimeIterator)resolved).getBaseCollection().getConstraint());
// else
// argTypes.add(o.getClass());
// }
// otherwise use the runtime type
argTypes.add(o.getClass());
}
// see if in cache
MethodDispatch methodDispatch;
List key = Arrays.asList(new Object[] { resolutionType, this.methodName, argTypes });
methodDispatch = (MethodDispatch) CompiledOperation.cache.get(key);
if (methodDispatch == null) {
try {
methodDispatch = new MethodDispatch(resolutionType, this.methodName, argTypes);
} catch (NameResolutionException nre) {
if (!org.apache.geode.cache.query.Struct.class.isAssignableFrom(resolutionType) && (DefaultQueryService.QUERY_HETEROGENEOUS_OBJECTS || DefaultQueryService.TEST_QUERY_HETEROGENEOUS_OBJECTS)) {
return QueryService.UNDEFINED;
} else {
throw nre;
}
}
// cache
CompiledOperation.cache.putIfAbsent(key, methodDispatch);
}
if (receiver instanceof PdxInstance) {
try {
if (receiver instanceof PdxInstanceImpl) {
receiver = ((PdxInstanceImpl) receiver).getCachedObject();
} else {
receiver = ((PdxInstance) receiver).getObject();
}
} catch (PdxSerializationException ex) {
throw new QueryInvocationTargetException(ex);
}
} else if (receiver instanceof PdxString) {
receiver = ((PdxString) receiver).toString();
}
return methodDispatch.invoke(receiver, args);
}
use of org.apache.geode.pdx.internal.PdxInstanceImpl in project geode by apache.
the class AutoSerializableJUnitTest method testPrimitiveObjects.
@Test
public void testPrimitiveObjects() throws Exception {
setupSerializer(new PrimitiveObjectsAutoSerializer(true, "org.apache.geode.pdx.AutoSerializableJUnitTest.PrimitiveObjectHolder"), true);
PrimitiveObjectHolder nullHolder = new PrimitiveObjectHolder();
PrimitiveObjectHolder defaultHolder = new PrimitiveObjectHolder();
defaultHolder.bool = false;
defaultHolder.b = 0;
defaultHolder.c = 0;
defaultHolder.s = 0;
defaultHolder.i = 0;
defaultHolder.l = 0L;
defaultHolder.f = 0.0f;
defaultHolder.d = 0.0;
HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
DataSerializer.writeObject(nullHolder, out);
PdxInstance pi = DataSerializer.readObject(new DataInputStream(new ByteArrayInputStream(out.toByteArray())));
PdxField pf = ((PdxInstanceImpl) pi).getPdxField("f");
assertEquals(FieldType.FLOAT, pf.getFieldType());
Object dObj = pi.getObject();
assertFalse(nullHolder.equals(dObj));
assertEquals(defaultHolder, dObj);
out = new HeapDataOutputStream(Version.CURRENT);
DataSerializer.writeObject(defaultHolder, out);
pi = DataSerializer.readObject(new DataInputStream(new ByteArrayInputStream(out.toByteArray())));
dObj = pi.getObject();
assertEquals(defaultHolder, dObj);
}
Aggregations