use of org.apache.geode.cache.PartitionAttributes in project geode by apache.
the class PartitionedRegionCqQueryDUnitTest method createServerWithoutRootRegion.
/**
* Create a bridge server with partitioned region.
*
* @param server VM where to create the bridge server.
* @param port bridge server port.
* @param isAccessor if true the under lying partitioned region will not host data on this vm.
* @param redundantCopies number of redundant copies for the primary bucket.
*/
public void createServerWithoutRootRegion(VM server, final int port, final boolean isAccessor, final int redundantCopies) {
SerializableRunnable createServer = new CacheSerializableRunnable("Create Cache Server") {
public void run2() throws CacheException {
LogWriterUtils.getLogWriter().info("### Create Cache Server. ###");
AttributesFactory attr = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
if (isAccessor) {
paf.setLocalMaxMemory(0);
}
PartitionAttributes prAttr = paf.setTotalNumBuckets(1).setRedundantCopies(redundantCopies).create();
attr.setPartitionAttributes(prAttr);
assertFalse(getSystem().isLoner());
// 0);
for (int i = 0; i < regions.length; i++) {
Region r = createRegionWithoutRoot(regions[i], attr.create());
LogWriterUtils.getLogWriter().info("Server created the region: " + r);
}
try {
startBridgeServer(port, true);
} catch (Exception ex) {
Assert.fail("While starting CacheServer", ex);
}
}
private Region createRegionWithoutRoot(String regionName, RegionAttributes create) {
getCache().createRegion(regionName, create);
return null;
}
};
server.invoke(createServer);
}
use of org.apache.geode.cache.PartitionAttributes in project geode by apache.
the class PersistentPartitionedRegionDUnitTest method createChildPR.
private void createChildPR(VM vm) {
vm.invoke(() -> {
PartitionAttributes PRatts = new PartitionAttributesFactory().setColocatedWith(PR_REGION_NAME).create();
PartitionedRegion child = (PartitionedRegion) PartitionedRegionTestHelper.createPartionedRegion("CHILD", PRatts);
});
}
use of org.apache.geode.cache.PartitionAttributes in project geode by apache.
the class CreateAlterDestroyRegionCommandsDUnitTest method testCreateRegionWithPartitionResolver.
/**
* Test Description 1. Deploy a JAR with Custom Partition Resolver 2. Create Region with Partition
* Resolver 3. Region should get created with no Errors 4. Verify Region Partition Attributes for
* Partition Resolver
*/
@Test
public void testCreateRegionWithPartitionResolver() throws IOException {
setUpJmxManagerOnVm0ThenConnect(null);
VM vm = Host.getHost(0).getVM(1);
// Create a cache in vm 1
vm.invoke(() -> {
assertNotNull(getCache());
});
ClassBuilder classBuilder = new ClassBuilder();
// classBuilder.addToClassPath(".");
final File prJarFile = new File(temporaryFolder.getRoot().getCanonicalPath() + File.separator, "myPartitionResolver.jar");
this.filesToBeDeleted.add(prJarFile.getAbsolutePath());
byte[] jarBytes = classBuilder.createJarFromClassContent("com/cadrdunit/TestPartitionResolver", PR_STRING);
writeJarBytesToFile(prJarFile, jarBytes);
CommandResult cmdResult = executeCommand("deploy --jar=" + prJarFile.getAbsolutePath());
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Create a region with an unrecognized compressor
CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_REGION);
commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGION, "regionWithPartitionResolver");
commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, "PARTITION");
commandStringBuilder.addOption(CliStrings.CREATE_REGION__PARTITION_RESOLVER, "com.cadrdunit.TestPartitionResolver");
CommandResult cmdResult1 = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult1.getStatus());
// Assert that our region was not created
vm.invoke(() -> {
Region region = getCache().getRegion("regionWithPartitionResolver");
assertNotNull(region);
PartitionedRegion pr = (PartitionedRegion) region;
PartitionAttributes partitionAttributes = pr.getPartitionAttributes();
assertNotNull(partitionAttributes);
PartitionResolver partitionResolver = partitionAttributes.getPartitionResolver();
assertNotNull(partitionResolver);
assertEquals("TestPartitionResolver", partitionResolver.getName());
});
vm.invoke(() -> {
getCache().getRegion("regionWithPartitionResolver").destroyRegion();
});
}
use of org.apache.geode.cache.PartitionAttributes in project geode by apache.
the class LuceneIndexForPartitionedRegionTest method initializeScenario.
private Region initializeScenario(final boolean withPersistence, final String regionPath, final Cache cache, int localMaxMemory) {
PartitionedRegion region = mock(PartitionedRegion.class);
PartitionAttributes partitionAttributes = new PartitionAttributesFactory().setLocalMaxMemory(localMaxMemory).setTotalNumBuckets(103).create();
RegionAttributes regionAttributes = spy(createRegionAttributes(withPersistence, partitionAttributes));
ExtensionPoint extensionPoint = mock(ExtensionPoint.class);
when(cache.getRegion(regionPath)).thenReturn(region);
when(cache.getRegionAttributes(any())).thenReturn(regionAttributes);
when(region.getAttributes()).thenReturn(regionAttributes);
when(regionAttributes.getPartitionAttributes()).thenReturn(partitionAttributes);
when(region.getPartitionAttributes()).thenReturn(partitionAttributes);
when(region.getExtensionPoint()).thenReturn(extensionPoint);
return region;
}
use of org.apache.geode.cache.PartitionAttributes in project geode by apache.
the class PartitionedRegionDelayedRecoveryDUnitTest method testNoRecovery.
@Test
public void testNoRecovery() throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
SerializableRunnable createPrRegions = new SerializableRunnable("createRegions") {
public void run() {
Cache cache = getCache();
AttributesFactory attr = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRecoveryDelay(-1);
paf.setStartupRecoveryDelay(-1);
paf.setRedundantCopies(1);
PartitionAttributes prAttr = paf.create();
attr.setPartitionAttributes(prAttr);
cache.createRegion("region1", attr.create());
}
};
// create the region in 2 VMS
vm0.invoke(createPrRegions);
vm1.invoke(createPrRegions);
// Do 1 put, which should create 1 bucket on both Vms
vm0.invoke(new SerializableRunnable("putData") {
public void run() {
Cache cache = getCache();
PartitionedRegion region1 = (PartitionedRegion) cache.getRegion("region1");
region1.put("A", "B");
}
});
// create the PR on another region, which won't have the bucket
vm2.invoke(createPrRegions);
// destroy the region in 1 of the VM's that's hosting the bucket
vm1.invoke(new SerializableRunnable("Destroy region") {
public void run() {
Cache cache = getCache();
PartitionedRegion region1 = (PartitionedRegion) cache.getRegion("region1");
region1.localDestroyRegion();
}
});
// check to make sure we didn't make a copy of the low redundancy bucket
SerializableRunnable checkNoBucket = new SerializableRunnable("Check for bucket") {
public void run() {
Cache cache = getCache();
PartitionedRegion region1 = (PartitionedRegion) cache.getRegion("region1");
assertEquals(0, region1.getDataStore().getBucketsManaged());
}
};
// Wait for a bit, maybe the region will try to make a copy of the bucket
Thread.sleep(1000);
vm2.invoke(checkNoBucket);
// recreate the region on VM1
vm1.invoke(createPrRegions);
// Wait for a bit, maybe the region will try to make a copy of the bucket
Thread.sleep(1000);
vm1.invoke(checkNoBucket);
vm2.invoke(checkNoBucket);
}
Aggregations