Search in sources :

Example 81 with Cache

use of org.apache.geode.cache.Cache in project geode by apache.

the class SizingFlagDUnitTest method getEvictions.

private long getEvictions(VM vm0) {
    return (Long) vm0.invoke(new SerializableCallable() {

        public Object call() {
            Cache cache = getCache();
            LocalRegion region = (LocalRegion) cache.getRegion("region");
            return getEvictions(region);
        }
    });
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Cache(org.apache.geode.cache.Cache)

Example 82 with Cache

use of org.apache.geode.cache.Cache in project geode by apache.

the class SingleHopStatsDUnitTest method closeCacheAndDisconnect.

private void closeCacheAndDisconnect() {
    try {
        Cache cache = CacheFactory.getAnyInstance();
        if (cache != null && !cache.isClosed()) {
            cache.close();
            cache.getDistributedSystem().disconnect();
        }
    } catch (CacheClosedException e) {
    }
}
Also used : CacheClosedException(org.apache.geode.cache.CacheClosedException) Cache(org.apache.geode.cache.Cache)

Example 83 with Cache

use of org.apache.geode.cache.Cache in project geode by apache.

the class SizingFlagDUnitTest method prHostsBucketForKey.

private boolean prHostsBucketForKey(VM vm, final Object key) {
    Boolean result = (Boolean) vm.invoke(new SerializableCallable("prHostsBucketForKey") {

        public Object call() {
            Cache cache = getCache();
            DistributedMember myId = cache.getDistributedSystem().getDistributedMember();
            Region region = cache.getRegion("region");
            DistributedMember hostMember = PartitionRegionHelper.getPrimaryMemberForKey(region, key);
            if (hostMember == null) {
                throw new IllegalStateException("bucket for key " + key + " is not hosted!");
            }
            boolean res = Boolean.valueOf(myId.equals(hostMember));
            // cache.getLogger().info("DEBUG prHostsBucketForKey=" + res);
            return res;
        }
    });
    return result.booleanValue();
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) DistributedMember(org.apache.geode.distributed.DistributedMember) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache)

Example 84 with Cache

use of org.apache.geode.cache.Cache in project geode by apache.

the class SizingFlagDUnitTest method getObjectSizerInvocations.

private int getObjectSizerInvocations(VM vm0) {
    return (Integer) vm0.invoke(new SerializableCallable() {

        public Object call() {
            Cache cache = getCache();
            LocalRegion region = (LocalRegion) cache.getRegion("region");
            return getObjectSizerInvocations(region);
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Cache(org.apache.geode.cache.Cache)

Example 85 with Cache

use of org.apache.geode.cache.Cache in project geode by apache.

the class OnGroupsFunctionExecutionDUnitTest method testStreamingClientServerFunction.

@Test
public void testStreamingClientServerFunction() {
    Host host = Host.getHost(0);
    VM server0 = host.getVM(0);
    VM server1 = host.getVM(1);
    VM server2 = host.getVM(2);
    VM client = host.getVM(3);
    VM locator = Host.getLocator();
    final String regionName = getName();
    initVM(server0, "mg,g0", regionName, true);
    initVM(server1, "g1", regionName, true);
    initVM(server2, "g0,g1", regionName, true);
    final int locatorPort = getLocatorPort(locator);
    final String hostName = host.getHostName();
    client.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            try {
                Cache c = CacheFactory.getAnyInstance();
                c.close();
            } catch (CacheClosedException cce) {
            }
            disconnectFromDS();
            LogWriterUtils.getLogWriter().fine("SWAP:creating client cache");
            ClientCacheFactory ccf = new ClientCacheFactory();
            ccf.addPoolLocator(hostName, locatorPort);
            ccf.setPoolServerGroup("mg");
            ccf.set(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
            ClientCache c = ccf.create();
            c.getLogger().info("SWAP:invoking function from client on g0");
            Execution e = InternalFunctionService.onServers(c, "g0");
            ArrayList<Integer> l = (ArrayList<Integer>) e.execute(new OnGroupMultiResultFunction()).getResult();
            int sum = 0;
            for (int i = 0; i < l.size(); i++) {
                sum += l.get(i);
            }
            assertEquals(10, sum);
            return null;
        }
    });
    client.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            ClientCache c = ClientCacheFactory.getAnyInstance();
            c.getLogger().fine("SWAP:invoking function from client on mg");
            Execution e = InternalFunctionService.onServers(c, "mg");
            ArrayList<Integer> l = (ArrayList<Integer>) e.execute(new OnGroupMultiResultFunction()).getResult();
            int sum = 0;
            for (int i = 0; i < l.size(); i++) {
                sum += l.get(i);
            }
            assertEquals(5, sum);
            return null;
        }
    });
    client.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            ClientCache c = ClientCacheFactory.getAnyInstance();
            c.getLogger().fine("SWAP:invoking function from client on g0 g1");
            Execution e = InternalFunctionService.onServers(c, "g0", "g1");
            ArrayList<Integer> l = (ArrayList<Integer>) e.execute(new OnGroupMultiResultFunction()).getResult();
            int sum = 0;
            for (int i = 0; i < l.size(); i++) {
                sum += l.get(i);
            }
            assertEquals(15, sum);
            return null;
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Host(org.apache.geode.test.dunit.Host) CacheClosedException(org.apache.geode.cache.CacheClosedException) ClientCache(org.apache.geode.cache.client.ClientCache) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) Execution(org.apache.geode.cache.execute.Execution) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

Cache (org.apache.geode.cache.Cache)1044 Region (org.apache.geode.cache.Region)478 Test (org.junit.Test)476 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)292 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)277 VM (org.apache.geode.test.dunit.VM)264 Host (org.apache.geode.test.dunit.Host)230 AttributesFactory (org.apache.geode.cache.AttributesFactory)229 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)177 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)176 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)164 LocalRegion (org.apache.geode.internal.cache.LocalRegion)153 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)123 ClientCache (org.apache.geode.cache.client.ClientCache)117 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)112 Properties (java.util.Properties)101 CacheException (org.apache.geode.cache.CacheException)101 RegionAttributes (org.apache.geode.cache.RegionAttributes)99 QueryService (org.apache.geode.cache.query.QueryService)95 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)93