use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.
the class GemcachedBinaryClientJUnitTest method testCacheWriterException.
@SuppressWarnings("unchecked")
public void testCacheWriterException() throws Exception {
MemcachedClient client = createMemcachedClient();
assertTrue(client.set("key", 0, "value".getBytes()).get());
client.set("exceptionkey", 0, "exceptionvalue").get();
GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
Region region = cache.getRegion(GemFireMemcachedServer.REGION_NAME);
region.getAttributesMutator().setCacheWriter(new CacheWriterAdapter() {
@Override
public void beforeCreate(EntryEvent event) throws CacheWriterException {
if (event.getKey().equals(KeyWrapper.getWrappedKey("exceptionkey".getBytes()))) {
throw new RuntimeException("ExpectedStrings: Cache writer exception");
}
}
@Override
public void beforeUpdate(EntryEvent event) throws CacheWriterException {
if (event.getKey().equals(KeyWrapper.getWrappedKey("exceptionkey".getBytes()))) {
throw new RuntimeException("ExpectedStrings: Cache writer exception");
}
}
});
long start = System.nanoTime();
try {
client.set("exceptionkey", 0, "exceptionvalue").get();
throw new RuntimeException("expected exception not thrown");
} catch (ExecutionException e) {
// expected
}
assertTrue(client.set("key2", 0, "value2".getBytes()).get());
}
use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.
the class GemcachedBinaryClientJUnitTest method testCacheLoaderException.
@SuppressWarnings("unchecked")
public void testCacheLoaderException() throws Exception {
MemcachedClient client = createMemcachedClient();
assertTrue(client.set("key", 0, "value").get());
GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
Region region = cache.getRegion(GemFireMemcachedServer.REGION_NAME);
region.getAttributesMutator().setCacheLoader(new CacheLoader() {
@Override
public void close() {
}
@Override
public Object load(LoaderHelper helper) throws CacheLoaderException {
if (helper.getKey().equals(KeyWrapper.getWrappedKey("exceptionkey".getBytes()))) {
throw new RuntimeException("ExpectedStrings: Cache loader exception");
}
return null;
}
});
long start = System.nanoTime();
try {
client.get("exceptionkey");
throw new RuntimeException("expected exception not thrown");
} catch (Exception e) {
// expected
}
assertEquals("value", client.get("key"));
}
use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.
the class PdxAttributesJUnitTest method tearDown.
@After
public void tearDown() throws Exception {
GemFireCacheImpl instance = GemFireCacheImpl.getInstance();
if (instance != null) {
instance.close();
}
FileUtils.deleteDirectory(diskDir);
File[] defaultStoreFiles = new File(".").listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.startsWith("BACKUPPDXAttributes");
}
});
for (File file : defaultStoreFiles) {
FileUtils.forceDelete(file);
}
}
use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.
the class PdxTypeExportDUnitTest method testPeer.
@Test
public void testPeer() throws Exception {
Region r = getCache().getRegion("pdxtest");
r.get(1);
TypeRegistry tr = ((GemFireCacheImpl) getCache()).getPdxRegistry();
Collection<PdxType> types = tr.typeMap().values();
assertEquals(MyObjectPdx.class.getName(), types.iterator().next().getClassName());
Collection<EnumInfo> enums = tr.enumMap().values();
assertEquals(MyEnumPdx.const1.name(), enums.iterator().next().getEnum().name());
}
use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.
the class Fakes method cache.
/**
* A fake cache, which contains a fake distributed system, distribution manager, etc.
*/
public static GemFireCacheImpl cache() {
GemFireCacheImpl cache = mock(GemFireCacheImpl.class);
InternalDistributedSystem system = mock(InternalDistributedSystem.class);
DistributionConfig config = mock(DistributionConfig.class);
DistributionManager distributionManager = mock(DistributionManager.class);
CancelCriterion systemCancelCriterion = mock(CancelCriterion.class);
DSClock clock = mock(DSClock.class);
LogWriter logger = mock(LogWriter.class);
Statistics stats = mock(Statistics.class);
InternalDistributedMember member;
member = new InternalDistributedMember("localhost", 5555);
when(config.getCacheXmlFile()).thenReturn(new File(""));
when(config.getDeployWorkingDir()).thenReturn(new File("."));
when(cache.getDistributedSystem()).thenReturn(system);
when(cache.getInternalDistributedSystem()).thenReturn(system);
when(cache.getSystem()).thenReturn(system);
when(cache.getMyId()).thenReturn(member);
when(cache.getDistributionManager()).thenReturn(distributionManager);
when(cache.getCancelCriterion()).thenReturn(systemCancelCriterion);
when(cache.getCachePerfStats()).thenReturn(mock(CachePerfStats.class));
when(system.getDistributedMember()).thenReturn(member);
when(system.getConfig()).thenReturn(config);
when(system.getDistributionManager()).thenReturn(distributionManager);
when(system.getCancelCriterion()).thenReturn(systemCancelCriterion);
when(system.getClock()).thenReturn(clock);
when(system.getLogWriter()).thenReturn(logger);
when(system.createAtomicStatistics(any(), any(), anyLong())).thenReturn(stats);
when(system.createAtomicStatistics(any(), any())).thenReturn(stats);
when(distributionManager.getId()).thenReturn(member);
when(distributionManager.getDistributionManagerId()).thenReturn(member);
when(distributionManager.getConfig()).thenReturn(config);
when(distributionManager.getSystem()).thenReturn(system);
when(distributionManager.getCancelCriterion()).thenReturn(systemCancelCriterion);
return cache;
}
Aggregations