Search in sources :

Example 61 with PartitionAttributesFactory

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

the class PartitionedRegionMembershipListenerDUnitTest method createSubRegionAttributes.

@Override
protected RegionAttributes createSubRegionAttributes(CacheListener[] cacheListeners) {
    AttributesFactory af = new AttributesFactory();
    if (cacheListeners != null) {
        af.initCacheListeners(cacheListeners);
    }
    af.setPartitionAttributes(new PartitionAttributesFactory().setTotalNumBuckets(5).setRedundantCopies(0).create());
    return af.create();
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory)

Example 62 with PartitionAttributesFactory

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

the class TXOrderDUnitTest method testInternalRegionNotExposed.

@Test
public void testInternalRegionNotExposed() {
    Host host = Host.getHost(0);
    VM vm1 = host.getVM(0);
    VM vm2 = host.getVM(1);
    SerializableCallable createRegion = new SerializableCallable() {

        public Object call() throws Exception {
            ExposedRegionTransactionListener tl = new ExposedRegionTransactionListener();
            CacheTransactionManager ctm = getCache().getCacheTransactionManager();
            ctm.addListener(tl);
            ExposedRegionCacheListener cl = new ExposedRegionCacheListener();
            AttributesFactory af = new AttributesFactory();
            PartitionAttributes pa = new PartitionAttributesFactory().setRedundantCopies(1).setTotalNumBuckets(1).create();
            af.setPartitionAttributes(pa);
            af.addCacheListener(cl);
            Region pr = createRootRegion("testTxEventForRegion", af.create());
            return null;
        }
    };
    vm1.invoke(createRegion);
    vm2.invoke(createRegion);
    vm1.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region pr = getRootRegion("testTxEventForRegion");
            CacheTransactionManager ctm = getCache().getCacheTransactionManager();
            pr.put(2, "tw");
            pr.put(3, "three");
            pr.put(4, "four");
            ctm.begin();
            pr.put(1, "one");
            pr.put(2, "two");
            pr.invalidate(3);
            pr.destroy(4);
            ctm.commit();
            return null;
        }
    });
    SerializableCallable verifyListener = new SerializableCallable() {

        public Object call() throws Exception {
            Region pr = getRootRegion("testTxEventForRegion");
            CacheTransactionManager ctm = getCache().getCacheTransactionManager();
            ExposedRegionTransactionListener tl = (ExposedRegionTransactionListener) ctm.getListeners()[0];
            ExposedRegionCacheListener cl = (ExposedRegionCacheListener) pr.getAttributes().getCacheListeners()[0];
            assertFalse(tl.exceptionOccurred);
            assertFalse(cl.exceptionOccurred);
            return null;
        }
    };
    vm1.invoke(verifyListener);
    vm2.invoke(verifyListener);
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) CacheException(org.apache.geode.cache.CacheException) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 63 with PartitionAttributesFactory

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

the class DistributedTransactionDUnitTest method getPersistentPRAttributes.

protected RegionAttributes getPersistentPRAttributes(final int redundancy, final int recoveryDelay, Cache cache, int numBuckets, boolean synchronous) {
    DiskStore ds = cache.findDiskStore("disk");
    if (ds == null) {
        ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
    }
    AttributesFactory af = new AttributesFactory();
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    paf.setRedundantCopies(redundancy);
    paf.setRecoveryDelay(recoveryDelay);
    paf.setTotalNumBuckets(numBuckets);
    paf.setLocalMaxMemory(500);
    af.setPartitionAttributes(paf.create());
    af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
    af.setDiskStoreName("disk");
    af.setDiskSynchronous(synchronous);
    RegionAttributes attr = af.create();
    return attr;
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes)

Example 64 with PartitionAttributesFactory

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

the class DistributedTransactionDUnitTest method createPR.

void createPR(boolean accessor, int redundantCopies, InterestPolicy interestPolicy) {
    AttributesFactory af = new AttributesFactory();
    af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
    if (interestPolicy != null) {
        af.setSubscriptionAttributes(new SubscriptionAttributes(interestPolicy));
    }
    af.setPartitionAttributes(new PartitionAttributesFactory<CustId, Customer>().setTotalNumBuckets(4).setLocalMaxMemory(accessor ? 0 : 1).setPartitionResolver(new CustomerIDPartitionResolver("resolver1")).setRedundantCopies(redundantCopies).create());
    getCache().createRegion(CUSTOMER_PR, af.create());
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CustomerIDPartitionResolver(org.apache.geode.internal.cache.execute.CustomerIDPartitionResolver) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes)

Example 65 with PartitionAttributesFactory

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

the class DistributedTransactionDUnitTest method testNonColocatedPutByPartitioning.

/*
   * We create 2 partitioned regions one on each server and have a third node as accessor and fire
   * transactional operations on it.
   */
@Test
public void testNonColocatedPutByPartitioning() {
    Host host = Host.getHost(0);
    // datastore
    VM server1 = host.getVM(0);
    // datastore
    VM server2 = host.getVM(1);
    // accessor
    VM server3 = host.getVM(2);
    final String CUSTOMER_PR1 = "CUSTOMER_PR1";
    final String CUSTOMER_PR2 = "CUSTOMER_PR2";
    // Create CUSTOMER_PR1 on server1
    execute(server1, new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            AttributesFactory af = new AttributesFactory();
            af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
            af.setPartitionAttributes(new PartitionAttributesFactory<CustId, Customer>().setTotalNumBuckets(4).setLocalMaxMemory(1).setPartitionResolver(new CustomerIDPartitionResolver("resolver1")).setRedundantCopies(0).create());
            getCache().createRegion(CUSTOMER_PR1, af.create());
            return null;
        }
    });
    // Create CUSTOMER_PR2 on server2
    execute(server2, new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            AttributesFactory af = new AttributesFactory();
            af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
            af.setPartitionAttributes(new PartitionAttributesFactory<CustId, Customer>().setTotalNumBuckets(4).setLocalMaxMemory(1).setPartitionResolver(new CustomerIDPartitionResolver("resolver2")).setRedundantCopies(0).create());
            getCache().createRegion(CUSTOMER_PR2, af.create());
            return null;
        }
    });
    // Create both the regions on server3 (accessor)
    execute(server3, new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            AttributesFactory af = new AttributesFactory();
            af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
            af.setPartitionAttributes(new PartitionAttributesFactory<CustId, Customer>().setTotalNumBuckets(4).setLocalMaxMemory(// since this is an accessor
            0).setPartitionResolver(new CustomerIDPartitionResolver("resolver1")).setRedundantCopies(0).create());
            getCache().createRegion(CUSTOMER_PR1, af.create());
            return null;
        }
    });
    execute(server3, new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            AttributesFactory af = new AttributesFactory();
            af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
            af.setPartitionAttributes(new PartitionAttributesFactory<CustId, Customer>().setTotalNumBuckets(4).setLocalMaxMemory(// since this is an accessor
            0).setPartitionResolver(new CustomerIDPartitionResolver("resolver2")).setRedundantCopies(0).create());
            getCache().createRegion(CUSTOMER_PR2, af.create());
            return null;
        }
    });
    // Now perform tx ops on accessor
    execute(server3, new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            CacheTransactionManager mgr = getGemfireCache().getTxManager();
            mgr.setDistributed(true);
            mgr.begin();
            Region<CustId, Customer> custPR1 = getCache().getRegion(CUSTOMER_PR1);
            CustId custIdOne = new CustId(1);
            Customer customerOne = new Customer("name1", "addr1");
            custPR1.put(custIdOne, customerOne);
            Region<CustId, Customer> custPR2 = getCache().getRegion(CUSTOMER_PR2);
            custPR2.put(custIdOne, customerOne);
            mgr.commit();
            // Verify
            assertEquals(1, custPR1.size());
            assertEquals(1, custPR2.size());
            return null;
        }
    });
    // Verify on one of the servers
    execute(server1, new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            Region<CustId, Customer> custPR1 = getCache().getRegion(CUSTOMER_PR1);
            assertEquals(1, custPR1.size());
            CustId custIdOne = new CustId(1);
            Customer customerOne = new Customer("name1", "addr1");
            assertEquals(customerOne, custPR1.get(custIdOne));
            return null;
        }
    });
}
Also used : Customer(org.apache.geode.internal.cache.execute.data.Customer) CustomerIDPartitionResolver(org.apache.geode.internal.cache.execute.CustomerIDPartitionResolver) 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) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CustId(org.apache.geode.internal.cache.execute.data.CustId) 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) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)340 AttributesFactory (org.apache.geode.cache.AttributesFactory)289 Region (org.apache.geode.cache.Region)173 Test (org.junit.Test)154 Cache (org.apache.geode.cache.Cache)136 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)116 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)112 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)110 VM (org.apache.geode.test.dunit.VM)101 Host (org.apache.geode.test.dunit.Host)99 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)95 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)75 CacheException (org.apache.geode.cache.CacheException)58 LocalRegion (org.apache.geode.internal.cache.LocalRegion)48 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)47 IOException (java.io.IOException)42 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)42 DiskStore (org.apache.geode.cache.DiskStore)41 RegionAttributes (org.apache.geode.cache.RegionAttributes)41 BucketRegion (org.apache.geode.internal.cache.BucketRegion)35