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();
}
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);
}
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;
}
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());
}
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;
}
});
}
Aggregations