Search in sources :

Example 76 with SerializableCallable

use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.

the class ShutdownAllDUnitTest method getBucketList.

protected Set<Integer> getBucketList(VM vm, final String regionName) {
    SerializableCallable getBuckets = new SerializableCallable("get buckets") {

        public Object call() throws Exception {
            Cache cache = getCache();
            Region region = cache.getRegion(regionName);
            if (region instanceof PartitionedRegion) {
                PartitionedRegion pr = (PartitionedRegion) region;
                return new TreeSet<Integer>(pr.getDataStore().getAllLocalBucketIds());
            } else {
                return null;
            }
        }
    };
    return (Set<Integer>) vm.invoke(getBuckets);
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) TreeSet(java.util.TreeSet) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) DiskRegion(org.apache.geode.internal.cache.DiskRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) InternalCache(org.apache.geode.internal.cache.InternalCache) Cache(org.apache.geode.cache.Cache)

Example 77 with SerializableCallable

use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.

the class PersistentPartitionedRegionDUnitTest method testNonPersistentProxy.

@Test
public void testNonPersistentProxy() {
    Host host = Host.getHost(0);
    VM vm1 = host.getVM(0);
    VM vm2 = host.getVM(1);
    VM vm3 = host.getVM(2);
    final String regionName = getName();
    SerializableCallable createAccessor = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            getCache().createRegionFactory(RegionShortcut.PARTITION_PROXY).create(regionName);
            return null;
        }
    };
    vm1.invoke(createAccessor);
    vm2.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            Region r = getCache().createRegionFactory(RegionShortcut.PARTITION_PERSISTENT).create(regionName);
            assertTrue(r.getAttributes().getConcurrencyChecksEnabled());
            return null;
        }
    });
    vm3.invoke(createAccessor);
    SerializableCallable verifyConcurrencyChecks = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            Region r = getCache().getRegion(regionName);
            assertTrue(r.getAttributes().getConcurrencyChecksEnabled());
            return null;
        }
    };
    vm1.invoke(verifyConcurrencyChecks);
    vm3.invoke(verifyConcurrencyChecks);
}
Also used : VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) RevokeFailedException(org.apache.geode.cache.persistence.RevokeFailedException) RevokedPersistentDataException(org.apache.geode.cache.persistence.RevokedPersistentDataException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) DiskAccessException(org.apache.geode.cache.DiskAccessException) ConcurrentModificationException(java.util.ConcurrentModificationException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) RMIException(org.apache.geode.test.dunit.RMIException) CacheClosedException(org.apache.geode.cache.CacheClosedException) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IOException(java.io.IOException) ReplyException(org.apache.geode.distributed.internal.ReplyException) QueryException(org.apache.geode.cache.query.QueryException) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 78 with SerializableCallable

use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.

the class PersistentPartitionedRegionDUnitTest method testCloseDuringRegionOperation.

@Test
public void testCloseDuringRegionOperation() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    createPR(vm0, 1, -1, 1);
    createPR(vm1, 1, -1, 1);
    // Make sure we create a bucket
    createData(vm1, 0, 1, "a");
    // Try to make sure there are some operations in flight while closing the cache
    SerializableCallable createData = new SerializableCallable() {

        public Object call() {
            Cache cache = getCache();
            Region region = cache.getRegion(PR_REGION_NAME);
            int i = 0;
            while (true) {
                try {
                    region.put(0, i);
                    i++;
                } catch (CacheClosedException e) {
                    break;
                }
            }
            return i - 1;
        }
    };
    AsyncInvocation asyncCreate = vm0.invokeAsync(createData);
    SerializableCallable waitForIntValue = new SerializableCallable() {

        public Object call() {
            Cache cache = getCache();
            Region region = cache.getRegion(PR_REGION_NAME);
            // The value is initialized as a String so wait
            // for it to be changed to an Integer.
            await().atMost(60, SECONDS).until(() -> {
                return region.get(0) instanceof Integer;
            });
            return region.get(0);
        }
    };
    vm0.invoke(waitForIntValue);
    vm1.invoke(waitForIntValue);
    AsyncInvocation close0 = closeCacheAsync(vm0);
    AsyncInvocation close1 = closeCacheAsync(vm1);
    // wait for the close to finish
    close0.getResult();
    close1.getResult();
    Integer lastSuccessfulInt = (Integer) asyncCreate.getResult();
    System.err.println("Cache was closed on integer " + lastSuccessfulInt);
    AsyncInvocation create1 = createPRAsync(vm0, 1, -1, 1);
    AsyncInvocation create2 = createPRAsync(vm1, 1, -1, 1);
    create1.getResult(MAX_WAIT);
    create2.getResult(MAX_WAIT);
    SerializableCallable getValue = new SerializableCallable() {

        public Object call() {
            Cache cache = getCache();
            Region region = cache.getRegion(PR_REGION_NAME);
            int value = (Integer) region.get(0);
            return value;
        }
    };
    int vm1Value = (Integer) vm0.invoke(getValue);
    int vm2Value = (Integer) vm1.invoke(getValue);
    assertEquals(vm1Value, vm2Value);
    assertTrue("value = " + vm1Value + ", lastSuccessfulInt=" + lastSuccessfulInt, vm1Value == lastSuccessfulInt || vm1Value == lastSuccessfulInt + 1);
}
Also used : VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) CacheClosedException(org.apache.geode.cache.CacheClosedException) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 79 with SerializableCallable

use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.

the class PersistentPartitionedRegionTestBase method moveBucket.

protected boolean moveBucket(final int bucketId, VM source, VM target) {
    SerializableCallable getId = new SerializableCallable("Get Id") {

        public Object call() throws Exception {
            Cache cache = getCache();
            return cache.getDistributedSystem().getDistributedMember();
        }
    };
    final InternalDistributedMember sourceId = (InternalDistributedMember) source.invoke(getId);
    SerializableCallable move = new SerializableCallable("move bucket") {

        public Object call() {
            Cache cache = getCache();
            PartitionedRegion region = (PartitionedRegion) cache.getRegion(PR_REGION_NAME);
            return region.getDataStore().moveBucket(bucketId, sourceId, false);
        }
    };
    return (Boolean) target.invoke(move);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Cache(org.apache.geode.cache.Cache)

Example 80 with SerializableCallable

use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.

the class PersistentPartitionedRegionTestBase method backup.

// used for above test
protected BackupStatus backup(VM vm) {
    return (BackupStatus) vm.invoke(new SerializableCallable("Backup all members") {

        public Object call() {
            DistributedSystemConfig config;
            AdminDistributedSystem adminDS = null;
            try {
                config = AdminDistributedSystemFactory.defineDistributedSystem(getSystem(), "");
                adminDS = AdminDistributedSystemFactory.getDistributedSystem(config);
                adminDS.connect();
                adminDS.waitToBeConnected(MAX_WAIT);
                return adminDS.backupAllMembers(getBackupDir());
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                if (adminDS != null) {
                    adminDS.disconnect();
                }
            }
        }
    });
}
Also used : DistributedSystemConfig(org.apache.geode.admin.DistributedSystemConfig) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) AdminDistributedSystem(org.apache.geode.admin.AdminDistributedSystem) AdminException(org.apache.geode.admin.AdminException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) IOException(java.io.IOException) BackupStatus(org.apache.geode.admin.BackupStatus)

Aggregations

SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)502 VM (org.apache.geode.test.dunit.VM)326 Test (org.junit.Test)314 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)311 Host (org.apache.geode.test.dunit.Host)306 Region (org.apache.geode.cache.Region)224 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)157 IgnoredException (org.apache.geode.test.dunit.IgnoredException)155 AttributesFactory (org.apache.geode.cache.AttributesFactory)139 Cache (org.apache.geode.cache.Cache)109 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)95 FunctionException (org.apache.geode.cache.execute.FunctionException)88 ArrayList (java.util.ArrayList)83 HashSet (java.util.HashSet)83 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)77 Execution (org.apache.geode.cache.execute.Execution)74 CommitConflictException (org.apache.geode.cache.CommitConflictException)70 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)66 Function (org.apache.geode.cache.execute.Function)63 IOException (java.io.IOException)62