use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class PersistentRecoveryOrderDUnitTest method createPersistentRegionAsync.
protected AsyncInvocation createPersistentRegionAsync(final VM vm, final boolean diskSynchronous) {
SerializableRunnable createRegion = new SerializableRunnable("Create persistent region") {
public void run() {
Cache cache = getCache();
DiskStoreFactory dsf = cache.createDiskStoreFactory();
File dir = getDiskDirForVM(vm);
dir.mkdirs();
dsf.setDiskDirs(new File[] { dir });
dsf.setMaxOplogSize(1);
DiskStore ds = dsf.create(REGION_NAME);
RegionFactory rf = new RegionFactory();
rf.setDiskStoreName(ds.getName());
rf.setDiskSynchronous(diskSynchronous);
rf.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
rf.setScope(Scope.DISTRIBUTED_ACK);
rf.create(REGION_NAME);
}
};
return vm.invokeAsync(createRegion);
}
use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class PersistentRVVRecoveryDUnitTest method testUpdateRVVWithAsyncPersistence.
/**
* Test that with concurrent updates to an async disk region, we correctly update the RVV On disk
*/
@Test
public void testUpdateRVVWithAsyncPersistence() throws Throwable {
Host host = Host.getHost(0);
final VM vm0 = host.getVM(1);
SerializableRunnable createRegion = new SerializableRunnable("Create persistent region") {
public void run() {
Cache cache = getCache();
DiskStoreFactory dsf = cache.createDiskStoreFactory();
File dir = getDiskDirForVM(vm0);
dir.mkdirs();
dsf.setDiskDirs(new File[] { dir });
dsf.setMaxOplogSize(1);
dsf.setQueueSize(100);
dsf.setTimeInterval(1000);
DiskStore ds = dsf.create(REGION_NAME);
RegionFactory rf = new RegionFactory();
rf.setDiskStoreName(ds.getName());
rf.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
rf.setScope(Scope.DISTRIBUTED_ACK);
rf.setDiskSynchronous(false);
rf.create(REGION_NAME);
}
};
// Create a region with async persistence
vm0.invoke(createRegion);
// In two different threads, perform updates to the same key on the same region
AsyncInvocation ins0 = vm0.invokeAsync(new SerializableRunnable("change the entry at vm0") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(REGION_NAME);
for (int i = 0; i < 500; i++) {
region.put("A", "vm0-" + i);
}
}
});
AsyncInvocation ins1 = vm0.invokeAsync(new SerializableRunnable("change the entry at vm1") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(REGION_NAME);
for (int i = 0; i < 500; i++) {
region.put("A", "vm1-" + i);
}
}
});
// Wait for the update threads to finish.
ins0.getResult(MAX_WAIT);
ins1.getResult(MAX_WAIT);
// Make sure the async queue is flushed to disk
vm0.invoke(new SerializableRunnable() {
@Override
public void run() {
Cache cache = getCache();
DiskStore ds = cache.findDiskStore(REGION_NAME);
ds.flush();
}
});
// Assert that the disk has seen all of the updates
RegionVersionVector rvv = getRVV(vm0);
RegionVersionVector diskRVV = getDiskRVV(vm0);
assertSameRVV(rvv, diskRVV);
// Bounce the cache and make the same assertion
closeCache(vm0);
vm0.invoke(createRegion);
// Assert that the recovered RVV is the same as before the restart
RegionVersionVector rvv2 = getRVV(vm0);
assertSameRVV(rvv, rvv2);
// The disk RVV should also match.
RegionVersionVector diskRVV2 = getDiskRVV(vm0);
assertSameRVV(rvv2, diskRVV2);
}
use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class ForceInvalidateEvictionDUnitTest method createPR.
private void createPR(VM vm) {
final String name = getUniqueName();
vm.invoke(new SerializableRunnable() {
public void run() {
Cache cache = getCache();
RegionFactory rf = new RegionFactory();
rf.setOffHeap(isOffHeapEnabled());
rf.setDataPolicy(DataPolicy.PARTITION);
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
paf.setTotalNumBuckets(5);
rf.setPartitionAttributes(paf.create());
rf.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(1));
rf.setConcurrencyChecksEnabled(false);
rf.create(name);
}
});
}
use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class ShowMetricsDUnitTest method testShowMetricsDefault.
/**
* tests the default version of "show metrics"
*/
@Test
public void testShowMetricsDefault() {
setUpJmxManagerOnVm0ThenConnect(null);
createLocalSetUp();
final VM vm1 = Host.getHost(0).getVM(1);
final String vm1Name = "VM" + vm1.getPid();
vm1.invoke(new SerializableRunnable() {
public void run() {
Properties localProps = new Properties();
localProps.setProperty(NAME, vm1Name);
getSystem(localProps);
Cache cache = getCache();
RegionFactory<Integer, Integer> dataRegionFactory = cache.createRegionFactory(RegionShortcut.REPLICATE);
Region region = dataRegionFactory.create("REGION1");
}
});
SerializableCallable showMetricCmd = new SerializableCallable() {
@Override
public Object call() throws Exception {
WaitCriterion wc = createMBeanWaitCriterion(1, "", null, 0);
waitForCriterion(wc, 5000, 500, true);
CommandProcessor commandProcessor = new CommandProcessor();
Result result = commandProcessor.createCommandStatement("show metrics", Collections.EMPTY_MAP).process();
String resultStr = commandResultToString((CommandResult) result);
getLogWriter().info(resultStr);
assertEquals(resultStr, true, result.getStatus().equals(Status.OK));
return resultStr;
}
};
// Invoke the command in the Manager VM
final VM managerVm = Host.getHost(0).getVM(0);
Object managerResultObj = managerVm.invoke(showMetricCmd);
String managerResult = (String) managerResultObj;
getLogWriter().info("#SB Manager");
getLogWriter().info(managerResult);
}
use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class ClientServerInvalidAndDestroyedEntryDUnitTest method getCreateServerCallable.
/* this method creates a server cache and is used by all of the tests in this class */
private SerializableCallableIF getCreateServerCallable(final String regionName, final boolean usePR) {
return new SerializableCallable("create server and entries") {
public Object call() {
Cache cache = getCache();
List<CacheServer> servers = cache.getCacheServers();
CacheServer server;
if (servers.size() > 0) {
server = servers.get(0);
} else {
server = cache.addCacheServer();
int port = AvailablePortHelper.getRandomAvailableTCPPort();
server.setPort(port);
server.setHostnameForClients("localhost");
try {
server.start();
} catch (IOException e) {
Assert.fail("Failed to start server ", e);
}
}
if (usePR) {
RegionFactory factory = cache.createRegionFactory(RegionShortcut.PARTITION);
PartitionAttributesFactory pf = new PartitionAttributesFactory();
pf.setTotalNumBuckets(2);
factory.setPartitionAttributes(pf.create());
factory.create(regionName);
} else {
cache.createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
}
return server.getPort();
}
};
}
Aggregations