Search in sources :

Example 51 with GemFireCacheImpl

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());
}
Also used : CacheWriterAdapter(org.apache.geode.cache.util.CacheWriterAdapter) MemcachedClient(net.spy.memcached.MemcachedClient) EntryEvent(org.apache.geode.cache.EntryEvent) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Region(org.apache.geode.cache.Region) ExecutionException(java.util.concurrent.ExecutionException) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 52 with GemFireCacheImpl

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"));
}
Also used : LoaderHelper(org.apache.geode.cache.LoaderHelper) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) MemcachedClient(net.spy.memcached.MemcachedClient) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Region(org.apache.geode.cache.Region) CacheLoader(org.apache.geode.cache.CacheLoader) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 53 with GemFireCacheImpl

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);
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) File(java.io.File) After(org.junit.After)

Example 54 with GemFireCacheImpl

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());
}
Also used : MyObjectPdx(com.examples.snapshot.MyObjectPdx) PdxType(org.apache.geode.pdx.internal.PdxType) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) Region(org.apache.geode.cache.Region) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) Test(org.junit.Test) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 55 with GemFireCacheImpl

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;
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) DSClock(org.apache.geode.distributed.internal.DSClock) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) LogWriter(org.apache.geode.LogWriter) CancelCriterion(org.apache.geode.CancelCriterion) CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Statistics(org.apache.geode.Statistics) File(java.io.File)

Aggregations

GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)213 Test (org.junit.Test)127 Region (org.apache.geode.cache.Region)86 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)55 LocalRegion (org.apache.geode.internal.cache.LocalRegion)54 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)51 VM (org.apache.geode.test.dunit.VM)49 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)47 Host (org.apache.geode.test.dunit.Host)42 ClientCacheCreation (org.apache.geode.internal.cache.xmlcache.ClientCacheCreation)40 RegionAttributes (org.apache.geode.cache.RegionAttributes)39 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)35 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)33 CacheException (org.apache.geode.cache.CacheException)32 RegionCreation (org.apache.geode.internal.cache.xmlcache.RegionCreation)32 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)31 Properties (java.util.Properties)24 AttributesFactory (org.apache.geode.cache.AttributesFactory)24 Cache (org.apache.geode.cache.Cache)23 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)23