"Port=5636, Addresses=127.0.0.1:6636");
OpenJPAEntityManagerFactory pmfReceiver = createDistinctFactory(
TCPRemoteCommitProvider.class,
"Port=6636, Addresses=127.0.0.1:5636");
// Get the datacaches from each pmf
DataCache dcSender =
((OpenJPAEntityManagerFactorySPI) pmfSender).getConfiguration()
.getDataCacheManagerInstance().getSystemDataCache();
DataCache dcReceiver =
((OpenJPAEntityManagerFactorySPI) pmfReceiver).getConfiguration()
.getDataCacheManagerInstance().getSystemDataCache();
deleteAll(RuntimeTest1.class);
deleteAll(RuntimeTest2.class);
_runtime1sOids = null;
_runtime2sOids = null;
String transType = "normal";
String rcpType = "OIDs";
if (asLargeTransaction) {
transType = "large";
rcpType = "classes";
}
System.out.println("-------------------");
System.out
.println(
"2 PMFs created, acting as a cluster using ports 5636 and 6636");
System.out.println("Testing scenario:");
System.out
.println(" 1 Seed datastore with instances of RuntimeTest1 AND "
+ "RuntimeTest2 objs.\n"
+ " 2 pmf2 fills its cache with both sets of objs.\n"
+ " 3 pmf1 does a "
+ transType
+ " tx that invokes an operation of "
+ changeOperation.getName()
+ " to affect a single Runtime1 \n"
+ " assert that both pmf1 and pmf2's data caches dropped all"
+ "Runtime1s");
System.out.println("Remote commit event is transmiting " + rcpType);
// Create runtimes1s and 2s.
// Noraml transaction
OpenJPAEntityManager pmSender = (OpenJPAEntityManager) pmfSender
.createEntityManager();
seedDataStore(pmSender, NUM_OBJECTS);
endEm(pmSender);
// wait a bit so they get stored
pause(1);
OpenJPAEntityManager pm2;
pm2 = (OpenJPAEntityManager) pmfReceiver.createEntityManager();
performLoadAll(pm2);
endEm(pm2);
pmSender = (OpenJPAEntityManager) pmfSender.createEntityManager();
performLoadAll(pmSender);
endEm(pmSender);
// assert that pmf2's data cache now has all the Runtime1 and 2s.
for (int i = 0; i < _runtime1sOids.length; i++) {
assertTrue(dcReceiver.contains(
Id.newInstance(RuntimeTest1.class, _runtime1sOids[i])));
}
for (int i = 0; i < _runtime2sOids.length; i++) {
assertTrue(dcReceiver.contains(
Id.newInstance(RuntimeTest2.class, _runtime2sOids[i])));
}
// Modify or delete exactly 1 RuntimeTest1 object during a
// largeTransaction
changeOperation.operation(pmfSender, asLargeTransaction);
// assert that pmf1's data cache now only has Runtime2 objects
if (asLargeTransaction) {
for (int i = 0; i < _runtime1sOids.length; i++) {
assertFalse(dcSender.contains(
Id.newInstance(RuntimeTest1.class, _runtime1sOids[i])));
}
} else {
// Normal transaction
for (int i = 0; i < _runtime1sOids.length; i++) {
if (isDelete && i == 0) {
assertFalse(dcSender.contains(
Id.newInstance(RuntimeTest1.class, _runtime1sOids[i])));
} else {
// modified the first elemnt, which just updated it.
// (for Kodo's data cache).
assertTrue(dcSender.contains(
Id.newInstance(RuntimeTest1.class, _runtime1sOids[i])));
}
}
}
for (int i = 0; i < _runtime2sOids.length; i++) {
assertTrue(dcSender.contains(
Id.newInstance(RuntimeTest2.class, _runtime2sOids[i])));
}
// wait a tiny bit so the rce propagates
pause(2);
// assert the pmf2's data cache also now only has Runtime2 objects
if (asLargeTransaction) {
for (int i = 0; i < _runtime1sOids.length; i++) {
assertFalse(dcReceiver.contains(Id.newInstance(
RuntimeTest1.class, _runtime1sOids[i]))); //failing here
}
} else {
for (int i = 0; i < _runtime1sOids.length; i++) {
if (i == 0) {
assertFalse(dcReceiver.contains(Id.newInstance(
RuntimeTest1.class,
_runtime1sOids[i]))); //failing here
} else {
assertTrue(dcReceiver.contains(
Id.newInstance(RuntimeTest1.class, _runtime1sOids[i])));
}
}
}
for (int i = 0; i < _runtime2sOids.length; i++) {
assertTrue(dcReceiver.contains(
Id.newInstance(RuntimeTest2.class, _runtime2sOids[i])));
}
// shutdown
pmfSender.close();