use of org.apache.geode.cache.CacheLoaderException in project geode by apache.
the class MultiVMRegionTestCase method testNoLoaderWithInvalidEntry.
/**
* Tests that a remote <code>CacheLoader</code> is not invoked if the remote region has an invalid
* entry (that is, a key, but no value).
*/
@Test
public void testNoLoaderWithInvalidEntry() throws Exception {
assumeTrue(supportsNetLoad());
final String name = this.getUniqueName();
final Object key = "KEY";
final Object value = "VALUE";
SerializableRunnable create = new CacheSerializableRunnable("Create Region") {
@Override
public void run2() throws CacheException {
Region region = createRegion(name);
loader = new TestCacheLoader() {
@Override
public Object load2(LoaderHelper helper) throws CacheLoaderException {
return value;
}
};
region.getAttributesMutator().setCacheLoader(loader);
}
};
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
vm0.invoke(create);
vm1.invoke(create);
vm1.invoke(new CacheSerializableRunnable("Create invalid entry") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
region.create(key, null);
}
});
vm0.invoke(new CacheSerializableRunnable("Remote get") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
assertEquals(value, region.get(key));
assertTrue(loader.wasInvoked());
}
});
vm1.invoke(new SerializableRunnable("Verify loader") {
@Override
public void run() {
assertFalse(loader.wasInvoked());
}
});
}
use of org.apache.geode.cache.CacheLoaderException in project geode by apache.
the class ProxyDUnitTest method distributedOps.
////////////////////// Test Methods //////////////////////
/**
* check distributed ops that originate in a PROXY are correctly distributed to non-proxy regions.
*/
private void distributedOps(DataPolicy dp, InterestPolicy ip) throws CacheException {
initOtherId();
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(dp);
af.setSubscriptionAttributes(new SubscriptionAttributes(ip));
af.setScope(Scope.DISTRIBUTED_ACK);
Region r = createRootRegion("ProxyDUnitTest", af.create());
doCreateOtherVm();
r.put("putkey", "putvalue1");
getOtherVm().invoke(new CacheSerializableRunnable("check put") {
public void run2() throws CacheException {
Region r = getRootRegion("ProxyDUnitTest");
assertEquals(true, r.containsKey("putkey"));
assertEquals("putvalue1", r.getEntry("putkey").getValue());
r.put("putkey", "putvalue2");
}
});
assertEquals(false, r.containsKey("putkey"));
// netsearch
assertEquals("putvalue2", r.get("putkey"));
r.invalidate("putkey");
getOtherVm().invoke(new CacheSerializableRunnable("check invalidate") {
public void run2() throws CacheException {
Region r = getRootRegion("ProxyDUnitTest");
assertEquals(true, r.containsKey("putkey"));
assertEquals(null, r.getEntry("putkey").getValue());
}
});
// invalid so total miss
assertEquals(null, r.get("putkey"));
r.destroy("putkey");
getOtherVm().invoke(new CacheSerializableRunnable("check destroy") {
public void run2() throws CacheException {
Region r = getRootRegion("ProxyDUnitTest");
assertEquals(false, r.containsKey("putkey"));
}
});
// total miss
assertEquals(null, r.get("putkey"));
r.create("createKey", "createValue1");
getOtherVm().invoke(new CacheSerializableRunnable("check create") {
public void run2() throws CacheException {
Region r = getRootRegion("ProxyDUnitTest");
assertEquals(true, r.containsKey("createKey"));
assertEquals("createValue1", r.getEntry("createKey").getValue());
}
});
{
Map m = new HashMap();
m.put("putAllKey1", "putAllValue1");
m.put("putAllKey2", "putAllValue2");
r.putAll(m, "putAllCallback");
}
getOtherVm().invoke(new CacheSerializableRunnable("check putAll") {
public void run2() throws CacheException {
Region r = getRootRegion("ProxyDUnitTest");
assertEquals(true, r.containsKey("putAllKey1"));
assertEquals("putAllValue1", r.getEntry("putAllKey1").getValue());
assertEquals(true, r.containsKey("putAllKey2"));
assertEquals("putAllValue2", r.getEntry("putAllKey2").getValue());
}
});
r.clear();
getOtherVm().invoke(new CacheSerializableRunnable("check clear") {
public void run2() throws CacheException {
Region r = getRootRegion("ProxyDUnitTest");
assertEquals(0, r.size());
}
});
getOtherVm().invoke(new CacheSerializableRunnable("install CacheWriter") {
public void run2() throws CacheException {
Region r = getRootRegion("ProxyDUnitTest");
AttributesMutator am = r.getAttributesMutator();
CacheWriter cw = new CacheWriterAdapter() {
public void beforeCreate(EntryEvent event) throws CacheWriterException {
throw new CacheWriterException("expected");
}
};
am.setCacheWriter(cw);
}
});
try {
r.put("putkey", "putvalue");
fail("expected CacheWriterException");
} catch (CacheWriterException expected) {
}
getOtherVm().invoke(new CacheSerializableRunnable("check clear") {
public void run2() throws CacheException {
Region r = getRootRegion("ProxyDUnitTest");
assertEquals(0, r.size());
}
});
// total miss
assertEquals(null, r.get("loadkey"));
getOtherVm().invoke(new CacheSerializableRunnable("install CacheLoader") {
public void run2() throws CacheException {
Region r = getRootRegion("ProxyDUnitTest");
AttributesMutator am = r.getAttributesMutator();
// clear csche writer
am.setCacheWriter(null);
CacheLoader cl = new CacheLoader() {
public Object load(LoaderHelper helper) throws CacheLoaderException {
if (helper.getKey().equals("loadkey")) {
return "loadvalue";
} else if (helper.getKey().equals("loadexception")) {
throw new CacheLoaderException("expected");
} else {
return null;
}
}
public void close() {
}
};
am.setCacheLoader(cl);
}
});
// net load
assertEquals("loadvalue", r.get("loadkey"));
// total miss
assertEquals(null, r.get("foobar"));
try {
r.get("loadexception");
fail("expected CacheLoaderException");
} catch (CacheLoaderException expected) {
}
r.destroyRegion();
getOtherVm().invoke(new CacheSerializableRunnable("check clear") {
public void run2() throws CacheException {
Region r = getRootRegion("ProxyDUnitTest");
assertEquals(null, r);
}
});
}
use of org.apache.geode.cache.CacheLoaderException in project geode by apache.
the class AbstractBaseController method getValue.
protected <T> T getValue(final String regionNamePath, final Object key, boolean postProcess) {
Assert.notNull(key, "The Cache Region key to read the value for cannot be null!");
Region r = getRegion(regionNamePath);
try {
Object value = r.get(key);
if (postProcess) {
return (T) securityService.postProcess(regionNamePath, key, value, false);
} else {
return (T) value;
}
} catch (SerializationException se) {
throw new DataTypeNotSupportedException("The resource identified could not convert into the supported content characteristics (JSON)!", se);
} catch (NullPointerException npe) {
throw new GemfireRestException(String.format("Resource (%1$s) configuration does not allow null keys!", regionNamePath), npe);
} catch (IllegalArgumentException iae) {
throw new GemfireRestException(String.format("Resource (%1$s) configuration does not allow requested operation on specified key!", regionNamePath), iae);
} catch (LeaseExpiredException lee) {
throw new GemfireRestException("Server has encountered error while processing this request!", lee);
} catch (TimeoutException te) {
throw new GemfireRestException("Server has encountered timeout error while processing this request!", te);
} catch (CacheLoaderException cle) {
throw new GemfireRestException("Server has encountered CacheLoader error while processing this request!", cle);
} catch (PartitionedRegionStorageException prse) {
throw new GemfireRestException("CacheLoader could not be invoked on partitioned region!", prse);
}
}
use of org.apache.geode.cache.CacheLoaderException in project geode by apache.
the class CqServiceImpl method closeCq.
@Override
public void closeCq(String cqName, ClientProxyMembershipID clientProxyId) throws CqException {
String serverCqName = cqName;
if (clientProxyId != null) {
serverCqName = this.constructServerCqName(cqName, clientProxyId);
removeFromCacheForServerToConstructedCQName(cqName, clientProxyId);
}
ServerCQImpl cQuery = null;
StringId errMsg = null;
Exception ex = null;
try {
HashMap<String, CqQueryImpl> cqMap = cqQueryMap;
if (!cqMap.containsKey(serverCqName)) {
/*
* gregp 052808: We should silently fail here instead of throwing error. This is to deal
* with races in recovery
*/
return;
}
cQuery = (ServerCQImpl) cqMap.get(serverCqName);
} catch (CacheLoaderException e1) {
errMsg = LocalizedStrings.CqService_CQ_NOT_FOUND_IN_THE_CQ_META_REGION_CQNAME_0;
ex = e1;
} catch (TimeoutException e2) {
errMsg = LocalizedStrings.CqService_TIMEOUT_WHILE_TRYING_TO_GET_CQ_FROM_META_REGION_CQNAME_0;
ex = e2;
} finally {
if (ex != null) {
String s = errMsg.toLocalizedString(cqName);
if (logger.isDebugEnabled()) {
logger.debug(s);
}
throw new CqException(s, ex);
}
}
try {
cQuery.close(false);
// CqBaseRegion
try {
LocalRegion baseRegion = cQuery.getCqBaseRegion();
if (baseRegion != null && !baseRegion.isDestroyed()) {
// Server specific clean up.
if (isServer()) {
FilterProfile fp = baseRegion.getFilterProfile();
if (fp != null) {
fp.closeCq(cQuery);
}
CacheClientProxy clientProxy = cQuery.getCacheClientNotifier().getClientProxy(clientProxyId);
clientProxy.decCqCount();
if (clientProxy.hasNoCq()) {
this.stats.decClientsWithCqs();
}
}
}
} catch (Exception e) {
// May be cache is being shutdown
if (logger.isDebugEnabled()) {
logger.debug("Failed to remove CQ from the base region. CqName : {}", cqName);
}
}
if (isServer()) {
removeFromBaseRegionToCqNameMap(cQuery.getRegionName(), serverCqName);
}
LocalRegion baseRegion = cQuery.getCqBaseRegion();
if (baseRegion.getFilterProfile().getCqCount() <= 0) {
if (logger.isDebugEnabled()) {
logger.debug("Should update the profile for this partitioned region {} for not requiring old value", baseRegion);
}
}
} catch (CqClosedException cce) {
throw new CqException(cce.getMessage());
} finally {
this.removeFromMatchingCqMap(cQuery);
}
}
use of org.apache.geode.cache.CacheLoaderException in project geode by apache.
the class LuceneQueriesIntegrationTest method shouldReturnCorrectResultsOnDeletionAfterQueryExecutionWithLoader.
@Test
public void shouldReturnCorrectResultsOnDeletionAfterQueryExecutionWithLoader() throws Exception {
final int pageSize = 2;
final LuceneQuery<Object, Object> query = addValuesAndCreateQuery(pageSize);
region.getAttributesMutator().setCacheLoader(new CacheLoader() {
@Override
public Object load(final LoaderHelper helper) throws CacheLoaderException {
return new TestObject("should not", "load this");
}
@Override
public void close() {
}
});
final PageableLuceneQueryResults<Object, Object> pages = query.findPages();
List<LuceneResultStruct<Object, Object>> allEntries = new ArrayList<>();
assertTrue(pages.hasNext());
assertEquals(7, pages.size());
// Destroying an entry from the region after the query is executed.
region.destroy("C");
final List<LuceneResultStruct<Object, Object>> page1 = pages.next();
assertEquals(pageSize, page1.size());
final List<LuceneResultStruct<Object, Object>> page2 = pages.next();
assertEquals(pageSize, page2.size());
final List<LuceneResultStruct<Object, Object>> page3 = pages.next();
assertEquals(pageSize, page3.size());
assertFalse(pages.hasNext());
allEntries.addAll(page1);
allEntries.addAll(page2);
allEntries.addAll(page3);
assertEquals(region.keySet(), allEntries.stream().map(entry -> entry.getKey()).collect(Collectors.toSet()));
assertEquals(region.values(), allEntries.stream().map(entry -> entry.getValue()).collect(Collectors.toSet()));
}
Aggregations