Search in sources :

Example 91 with SerializableCallable

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

the class DistributedTransactionDUnitTest method testTransactionalPutOnReplicatedRegion.

@Test
public void testTransactionalPutOnReplicatedRegion() throws Exception {
    Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM server2 = host.getVM(1);
    VM server3 = host.getVM(2);
    createRR(new VM[] { server1, server2, server3 });
    execute(server1, new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            CacheTransactionManager mgr = getGemfireCache().getTxManager();
            mgr.setDistributed(true);
            mgr.begin();
            mgr.commit();
            mgr.begin();
            Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER_RR);
            CustId custId = new CustId(1);
            Customer expectedCustomer = custRegion.get(custId);
            assertNull(expectedCustomer);
            // Perform a put
            CustId custIdOne = new CustId(1);
            Customer customerOne = new Customer("name1", "addr1");
            custRegion.put(custIdOne, customerOne);
            // Rollback the transaction
            mgr.rollback();
            mgr.begin();
            // Verify that the entry is rolled back
            expectedCustomer = custRegion.get(custId);
            assertNull(expectedCustomer);
            // Perform two more puts and a commit
            CustId custIdTwo = new CustId(2);
            Customer customerTwo = new Customer("name2", "addr2");
            CustId custIdThree = new CustId(3);
            Customer customerThree = new Customer("name3", "addr3");
            custRegion.put(custIdTwo, customerTwo);
            custRegion.put(custIdThree, customerThree);
            mgr.commit();
            mgr.begin();
            // Verify data
            assertEquals(2, custRegion.size());
            assertTrue(custRegion.containsKey(custIdTwo));
            assertTrue(custRegion.containsKey(custIdThree));
            assertEquals(customerTwo, custRegion.get(custIdTwo));
            assertEquals(customerThree, custRegion.get(custIdThree));
            // Perform one more put but don't commit
            custRegion.put(custIdOne, customerOne);
            // Verify data
            assertEquals(3, custRegion.size());
            assertTrue(custRegion.containsKey(custIdOne));
            assertEquals(customerOne, custRegion.get(custIdOne));
            mgr.commit();
            return null;
        }
    });
}
Also used : CustId(org.apache.geode.internal.cache.execute.data.CustId) Customer(org.apache.geode.internal.cache.execute.data.Customer) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Host(org.apache.geode.test.dunit.Host) CommitConflictException(org.apache.geode.cache.CommitConflictException) CommitIncompleteException(org.apache.geode.cache.CommitIncompleteException) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 92 with SerializableCallable

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

the class Bug45934DUnitTest method unsetRemoteFlag.

private void unsetRemoteFlag(final VM remote) {
    SerializableCallable create = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            AbstractUpdateOperation.test_InvalidVersion = false;
            return null;
        }
    };
    remote.invoke(create);
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable)

Example 93 with SerializableCallable

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

the class Bug45934DUnitTest method verify.

private void verify(VM vm, final String name, final int count) {
    SerializableCallable verify = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            Region<Integer, Integer> r = getCache().getRegion(name);
            assertEquals(count, r.size());
            for (int i = 0; i < count; i++) {
                assertEquals(i, (int) r.get(i));
            }
            return null;
        }
    };
    vm.invoke(verify);
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable)

Example 94 with SerializableCallable

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

the class Bug45934DUnitTest method createRemoteRegion.

private void createRemoteRegion(final VM remote, final String name) {
    SerializableCallable create = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            CacheFactory cf = new CacheFactory();
            cf.set(MCAST_PORT, "45934");
            cf.set(CONSERVE_SOCKETS, "false");
            getCache(cf).<Integer, Integer>createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT).create(name);
            AbstractUpdateOperation.test_InvalidVersion = true;
            return null;
        }
    };
    remote.invoke(create);
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) CacheFactory(org.apache.geode.cache.CacheFactory)

Example 95 with SerializableCallable

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

the class Bug41733DUnitTest method getBucketList.

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

        public Object call() throws Exception {
            Cache cache = getCache();
            PartitionedRegion region = (PartitionedRegion) cache.getRegion(regionName);
            return new TreeSet<Integer>(region.getDataStore().getAllLocalBucketIds());
        }
    };
    return (Set<Integer>) vm0.invoke(getBuckets);
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Cache(org.apache.geode.cache.Cache)

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