use of org.apache.geode.cache.AttributesFactory in project geode by apache.
the class CachedAllEventsDUnitTest method doCreateOtherVm.
private void doCreateOtherVm() {
VM vm = getOtherVm();
vm.invoke(new CacheSerializableRunnable("create root") {
public void run2() throws CacheException {
AttributesFactory af = new AttributesFactory();
af.setScope(Scope.DISTRIBUTED_ACK);
Region r1 = createRootRegion("r1", af.create());
r1.create("key", "value");
}
});
}
use of org.apache.geode.cache.AttributesFactory in project geode by apache.
the class CallbackArgDUnitTest method doCommitOtherVm.
private void doCommitOtherVm() {
VM vm = getOtherVm();
vm.invoke(new CacheSerializableRunnable("create root") {
public void run2() throws CacheException {
AttributesFactory af = new AttributesFactory();
CacheListener cl1 = new CacheListenerAdapter() {
public void afterCreate(EntryEvent e) {
assertEquals(callbackArg, e.getCallbackArgument());
}
};
af.addCacheListener(cl1);
af.setScope(Scope.DISTRIBUTED_ACK);
Region r1 = createRootRegion("r1", af.create());
Region r2 = r1.createSubregion("r2", af.create());
Region r3 = r2.createSubregion("r3", af.create());
CacheTransactionManager ctm = getCache().getCacheTransactionManager();
TransactionListener tl1 = new TransactionListenerAdapter() {
public void afterCommit(TransactionEvent e) {
assertEquals(6, e.getEvents().size());
Iterator it = e.getEvents().iterator();
while (it.hasNext()) {
EntryEvent ee = (EntryEvent) it.next();
assertEquals(callbackArg, ee.getCallbackArgument());
assertEquals(true, ee.isCallbackArgumentAvailable());
}
}
};
ctm.addListener(tl1);
ctm.begin();
r2.put("b", "value1", callbackArg);
r3.put("c", "value2", callbackArg);
r1.put("a", "value3", callbackArg);
r1.put("a2", "value4", callbackArg);
r3.put("c2", "value5", callbackArg);
r2.put("b2", "value6", callbackArg);
ctm.commit();
}
});
}
use of org.apache.geode.cache.AttributesFactory in project geode by apache.
the class SearchAndLoadDUnitTest method testOneHopNetWriteRemoteWriter.
/** same as the previous test but the cache writer is in a third, non-replicated, vm */
@Test
public void testOneHopNetWriteRemoteWriter() throws CacheException, InterruptedException {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
final String name = this.getUniqueName() + "Region";
final String objectName = "Object7";
final Integer value = new Integer(483);
final Integer updateValue = new Integer(484);
vm0.invoke(new SerializableRunnable("Create replicate Region") {
public void run() {
try {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
createRegion(name, factory.create());
} catch (CacheException ex) {
Assert.fail("While creating empty region", ex);
}
}
});
vm1.invoke(new SerializableRunnable("Create empty Region") {
public void run() {
try {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.EMPTY);
createRegion(name, factory.create());
} catch (CacheException ex) {
Assert.fail("While creating empty region", ex);
}
}
});
vm2.invoke(new SerializableRunnable("Create replicated region with cacheWriter") {
public void run() {
netWriteInvoked = false;
operationWasCreate = false;
originWasRemote = false;
writerInvocationCount = 0;
try {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.EMPTY);
factory.setCacheWriter(new CacheWriter() {
public void beforeCreate(EntryEvent e) throws CacheWriterException {
e.getRegion().getCache().getLogger().info("cache writer beforeCreate invoked for " + e);
netWriteInvoked = true;
operationWasCreate = true;
originWasRemote = e.isOriginRemote();
writerInvocationCount++;
return;
}
public void beforeUpdate(EntryEvent e) throws CacheWriterException {
e.getRegion().getCache().getLogger().info("cache writer beforeUpdate invoked for " + e);
netWriteInvoked = true;
operationWasCreate = false;
originWasRemote = e.isOriginRemote();
writerInvocationCount++;
return;
}
public void beforeDestroy(EntryEvent e) throws CacheWriterException {
}
public void beforeRegionDestroy(RegionEvent e) throws CacheWriterException {
}
public void beforeRegionClear(RegionEvent e) throws CacheWriterException {
}
public void close() {
}
});
createRegion(name, factory.create());
} catch (CacheException ex) {
Assert.fail("While creating replicated region", ex);
}
}
});
vm1.invoke(new SerializableRunnable("do a put that should be proxied in the other vm and invoke its cache writer") {
public void run() {
try {
getRootRegion().getSubregion(name).put(objectName, value);
} catch (CacheWriterException cwe) {
} catch (TimeoutException te) {
}
}
});
vm2.invoke(new SerializableRunnable("ensure that cache writer was invoked with correct settings in event") {
public void run() {
assertTrue("expected cache writer to be invoked", netWriteInvoked);
assertTrue("expected originRemote to be true", originWasRemote);
assertTrue("expected event to be create", operationWasCreate);
assertEquals("expected only one cache writer invocation", 1, writerInvocationCount);
// set flags for the next test - updating the same key
netWriteInvoked = false;
writerInvocationCount = 0;
}
});
vm1.invoke(new SerializableRunnable("do an update that should be proxied in the other vm and invoke its cache writer") {
public void run() {
try {
getRootRegion().getSubregion(name).put(objectName, updateValue);
} catch (CacheWriterException cwe) {
} catch (TimeoutException te) {
}
}
});
vm2.invoke(new SerializableRunnable("ensure that cache writer was invoked with correct settings in event") {
public void run() {
assertTrue("expected cache writer to be invoked", netWriteInvoked);
assertTrue("expected originRemote to be true", originWasRemote);
assertTrue("expected event to be create", operationWasCreate);
assertEquals("expected only one cache writer invocation", 1, writerInvocationCount);
}
});
}
use of org.apache.geode.cache.AttributesFactory in project geode by apache.
the class SearchAndLoadDUnitTest method testLocalLoad.
@Test
public void testLocalLoad() throws CacheException, InterruptedException {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
final String name = this.getUniqueName() + "-ACK";
final String objectName = "C";
final Integer value = new Integer(44);
remoteLoaderInvoked = false;
loaderInvoked = false;
vm0.invoke(new SerializableRunnable("Create ACK Region") {
public void run() {
remoteLoaderInvoked = false;
loaderInvoked = false;
try {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setEarlyAck(false);
factory.setCacheLoader(new CacheLoader() {
public Object load(LoaderHelper helper) {
loaderInvoked = true;
return value;
}
public void close() {
}
});
Region region = createRegion(name, factory.create());
region.create(objectName, null);
} catch (CacheException ex) {
Assert.fail("While creating ACK region", ex);
}
}
});
vm1.invoke(new SerializableRunnable("Create ACK Region") {
public void run() {
remoteLoaderInvoked = false;
loaderInvoked = false;
try {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setEarlyAck(false);
factory.setCacheLoader(new CacheLoader() {
public Object load(LoaderHelper helper) {
remoteLoaderInvoked = true;
return value;
}
public void close() {
}
});
createRegion(name, factory.create());
} catch (CacheException ex) {
Assert.fail("While creating ACK region", ex);
}
}
});
vm0.invoke(new SerializableRunnable("Get a value from local loader") {
public void run() {
try {
Object result = getRootRegion().getSubregion(name).get(objectName);
assertEquals(value, result);
assertEquals(new Boolean(loaderInvoked), Boolean.TRUE);
assertEquals(new Boolean(remoteLoaderInvoked), Boolean.FALSE);
} catch (CacheLoaderException cle) {
} catch (TimeoutException te) {
}
}
});
}
use of org.apache.geode.cache.AttributesFactory in project geode by apache.
the class RegionTestCase method testEntryIdleReset.
/**
* Verify that accessing an entry resets its idle time
*
* @throws Exception
*/
@Test
public void testEntryIdleReset() throws Exception {
final String name = this.getUniqueName();
// Test no longer waits for this timeout to expire
// seconds
final int timeout = 90;
final String key = "KEY";
final String value = "VALUE";
AttributesFactory factory = new AttributesFactory(getRegionAttributes());
ExpirationAttributes expire = new ExpirationAttributes(timeout, ExpirationAction.DESTROY);
factory.setEntryIdleTimeout(expire);
factory.setStatisticsEnabled(true);
RegionAttributes attrs = factory.create();
LocalRegion region = (LocalRegion) createRegion(name, attrs);
region.create(key, null);
EntryExpiryTask eet = region.getEntryExpiryTask(key);
long createExpiryTime = eet.getExpirationTime();
Wait.waitForExpiryClockToChange(region);
// touch
region.get(key);
assertSame(eet, region.getEntryExpiryTask(key));
long getExpiryTime = eet.getExpirationTime();
if (getExpiryTime - createExpiryTime <= 0L) {
fail("get did not reset the expiration time. createExpiryTime=" + createExpiryTime + " getExpiryTime=" + getExpiryTime);
}
Wait.waitForExpiryClockToChange(region);
// touch
region.put(key, value);
assertSame(eet, region.getEntryExpiryTask(key));
long putExpiryTime = eet.getExpirationTime();
if (putExpiryTime - getExpiryTime <= 0L) {
fail("put did not reset the expiration time. getExpiryTime=" + getExpiryTime + " putExpiryTime=" + putExpiryTime);
}
// TODO other ops that should be validated?
// Now verify operations that do not modify the expiry time
Wait.waitForExpiryClockToChange(region);
// touch
region.invalidate(key);
assertSame(eet, region.getEntryExpiryTask(key));
long invalidateExpiryTime = eet.getExpirationTime();
if (region.getConcurrencyChecksEnabled()) {
if (putExpiryTime - getExpiryTime <= 0L) {
fail("invalidate did not reset the expiration time. putExpiryTime=" + putExpiryTime + " invalidateExpiryTime=" + invalidateExpiryTime);
}
} else {
if (invalidateExpiryTime != putExpiryTime) {
fail("invalidate did reset the expiration time. putExpiryTime=" + putExpiryTime + " invalidateExpiryTime=" + invalidateExpiryTime);
}
}
}
Aggregations