use of org.apache.geode.internal.cache.execute.CustomerIDPartitionResolver in project geode by apache.
the class DistributedTransactionDUnitTest method testPutAllWithTransactions.
@Test
public void testPutAllWithTransactions() throws Exception {
Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
VM server3 = host.getVM(2);
createRegions(new VM[] { server1, server2, server3 });
execute(new VM[] { server1, server2, 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(1).setPartitionResolver(new CustomerIDPartitionResolver("resolver1")).setRedundantCopies(0).create());
getCache().createRegion("NONCOLOCATED_PR", af.create());
return null;
}
});
execute(server1, new SerializableCallable() {
@Override
public Object call() throws Exception {
Region custRegion = getCache().getRegion(CUSTOMER_PR);
Region orderRegion = getCache().getRegion(ORDER_PR);
Map custMap = new HashMap();
Map orderMap = new HashMap();
for (int i = 0; i < 5; i++) {
CustId custId = new CustId(i);
Customer customer = new Customer("customer" + i, "address" + i);
OrderId orderId = new OrderId(i, custId);
Order order = new Order("order" + i);
custMap.put(custId, customer);
orderMap.put(orderId, order);
}
CacheTransactionManager mgr = getGemfireCache().getTxManager();
mgr.setDistributed(true);
mgr.begin();
custRegion.putAll(custMap);
orderRegion.putAll(orderMap);
mgr.commit();
mgr.begin();
assertEquals(5, custRegion.size());
assertEquals(5, orderRegion.size());
custMap = new HashMap();
orderMap = new HashMap();
for (int i = 5; i < 10; i++) {
CustId custId = new CustId(i);
Customer customer = new Customer("customer" + i, "address" + i);
OrderId orderId = new OrderId(i, custId);
Order order = new Order("order" + i);
custMap.put(custId, customer);
orderMap.put(orderId, order);
}
custRegion.putAll(custMap);
orderRegion.putAll(orderMap);
mgr.rollback();
mgr.begin();
assertEquals(5, custRegion.size());
assertEquals(5, orderRegion.size());
custRegion.putAll(custMap);
orderRegion.putAll(orderMap);
assertEquals(10, custRegion.size());
assertEquals(10, orderRegion.size());
// Verify operations involving non colocated PR
Map map = new HashMap();
custMap.clear();
for (int i = 10; i < 15; i++) {
CustId custId = new CustId(i);
Customer customer = new Customer("customer" + i, "address" + i);
OrderId orderId = new OrderId(i, custId);
Order order = new Order("order" + i);
custMap.put(custId, customer);
map.put(custId, customer);
}
custRegion.putAll(custMap);
Region nonColocatedRegion = getCache().getRegion("NONCOLOCATED_PR");
nonColocatedRegion.putAll(orderMap);
mgr.commit();
mgr.begin();
assertEquals(15, custRegion.size());
assertEquals(5, nonColocatedRegion.size());
custMap.clear();
map.clear();
for (int i = 15; i < 20; i++) {
CustId custId = new CustId(i);
Customer customer = new Customer("customer" + i, "address" + i);
OrderId orderId = new OrderId(i, custId);
Order order = new Order("order" + i);
custMap.put(custId, customer);
map.put(custId, customer);
}
custRegion.putAll(custMap);
nonColocatedRegion.putAll(orderMap);
mgr.rollback();
assertEquals(15, custRegion.size());
assertEquals(5, nonColocatedRegion.size());
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.CustomerIDPartitionResolver in project geode by apache.
the class DistributedTransactionDUnitTest method testTxWithSingleDataStore.
@Test
public void testTxWithSingleDataStore() throws Exception {
Host host = Host.getHost(0);
// datastore
VM server1 = host.getVM(0);
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(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("resolver2")).setRedundantCopies(0).create());
getCache().createRegion(CUSTOMER_PR2, af.create());
return null;
}
});
// Now perform tx ops on accessor
execute(server1, 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;
}
});
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;
}
});
}
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());
}
use of org.apache.geode.internal.cache.execute.CustomerIDPartitionResolver in project geode by apache.
the class RemoteCQTransactionDUnitTest 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());
}
Aggregations