Search in sources :

Example 1 with CustomerIDPartitionResolver

use of org.apache.geode.internal.cache.execute.CustomerIDPartitionResolver in project geode by apache.

the class DistTXDebugDUnitTest method createPR.

public static void createPR(String partitionedRegionName, Integer redundancy, Integer localMaxMemory, Integer totalNumBuckets, Object colocatedWith, Boolean isPartitionResolver, Boolean concurrencyChecks) {
    PartitionAttributesFactory<String, String> paf = new PartitionAttributesFactory();
    paf.setRedundantCopies(redundancy);
    if (localMaxMemory != null) {
        paf.setLocalMaxMemory(localMaxMemory);
    }
    if (totalNumBuckets != null) {
        paf.setTotalNumBuckets(totalNumBuckets);
    }
    if (colocatedWith != null) {
        paf.setColocatedWith((String) colocatedWith);
    }
    if (isPartitionResolver) {
        paf.setPartitionResolver(new CustomerIDPartitionResolver("CustomerIDPartitionResolver"));
    }
    PartitionAttributes<String, String> prAttr = paf.create();
    AttributesFactory<String, String> attr = new AttributesFactory();
    attr.setPartitionAttributes(prAttr);
    attr.setConcurrencyChecksEnabled(concurrencyChecks);
    assertNotNull(basicGetCache());
    Region<String, String> pr = basicGetCache().createRegion(partitionedRegionName, attr.create());
    assertNotNull(pr);
    LogWriterUtils.getLogWriter().info("Partitioned Region " + partitionedRegionName + " created Successfully :" + pr.toString());
}
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)

Example 2 with CustomerIDPartitionResolver

use of org.apache.geode.internal.cache.execute.CustomerIDPartitionResolver 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 3 with CustomerIDPartitionResolver

use of org.apache.geode.internal.cache.execute.CustomerIDPartitionResolver 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)

Example 4 with CustomerIDPartitionResolver

use of org.apache.geode.internal.cache.execute.CustomerIDPartitionResolver in project geode by apache.

the class TransactionsWithDeltaDUnitTest method createRegion.

private void createRegion(boolean accessor, int redundantCopies, InterestPolicy interestPolicy) {
    AttributesFactory af = new AttributesFactory();
    af.setScope(Scope.DISTRIBUTED_ACK);
    af.setDataPolicy(DataPolicy.REPLICATE);
    af.setCloningEnabled(true);
    getCache().createRegion(D_REFERENCE, af.create());
    af = new AttributesFactory();
    af.setCloningEnabled(true);
    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, af.create());
    af.setPartitionAttributes(new PartitionAttributesFactory<OrderId, Order>().setTotalNumBuckets(4).setLocalMaxMemory(accessor ? 0 : 1).setPartitionResolver(new CustomerIDPartitionResolver("resolver2")).setRedundantCopies(redundantCopies).setColocatedWith(CUSTOMER).create());
    getCache().createRegion(ORDER, af.create());
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) CustomerIDPartitionResolver(org.apache.geode.internal.cache.execute.CustomerIDPartitionResolver) OrderId(org.apache.geode.internal.cache.execute.data.OrderId)

Example 5 with CustomerIDPartitionResolver

use of org.apache.geode.internal.cache.execute.CustomerIDPartitionResolver in project geode by apache.

the class RemoteTransactionDUnitTest method createRegion.

void createRegion(boolean accessor, int redundantCopies, InterestPolicy interestPolicy) {
    AttributesFactory af = new AttributesFactory();
    af.setScope(Scope.DISTRIBUTED_ACK);
    af.setDataPolicy(DataPolicy.REPLICATE);
    af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
    getCache().createRegion(D_REFERENCE, af.create());
    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, af.create());
    af.setPartitionAttributes(new PartitionAttributesFactory<OrderId, Order>().setTotalNumBuckets(4).setLocalMaxMemory(accessor ? 0 : 1).setPartitionResolver(new CustomerIDPartitionResolver("resolver2")).setRedundantCopies(redundantCopies).setColocatedWith(CUSTOMER).create());
    getCache().createRegion(ORDER, af.create());
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) 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) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes)

Aggregations

CustomerIDPartitionResolver (org.apache.geode.internal.cache.execute.CustomerIDPartitionResolver)9 AttributesFactory (org.apache.geode.cache.AttributesFactory)8 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)8 Order (org.apache.geode.internal.cache.execute.data.Order)5 OrderId (org.apache.geode.internal.cache.execute.data.OrderId)5 SubscriptionAttributes (org.apache.geode.cache.SubscriptionAttributes)4 CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)3 CommitConflictException (org.apache.geode.cache.CommitConflictException)3 CommitIncompleteException (org.apache.geode.cache.CommitIncompleteException)3 Region (org.apache.geode.cache.Region)3 BucketRegion (org.apache.geode.internal.cache.BucketRegion)3 LocalRegion (org.apache.geode.internal.cache.LocalRegion)3 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)3 CustId (org.apache.geode.internal.cache.execute.data.CustId)3 Customer (org.apache.geode.internal.cache.execute.data.Customer)3 Host (org.apache.geode.test.dunit.Host)3 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)3 VM (org.apache.geode.test.dunit.VM)3 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)3 Test (org.junit.Test)3