Search in sources :

Example 76 with PartitionAttributes

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);
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) RegionAttributes(org.apache.geode.cache.RegionAttributes) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 77 with PartitionAttributes

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);
    });
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) PartitionAttributes(org.apache.geode.cache.PartitionAttributes)

Example 78 with PartitionAttributes

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();
    });
}
Also used : CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) VM(org.apache.geode.test.dunit.VM) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) PartitionResolver(org.apache.geode.cache.PartitionResolver) ClassBuilder(org.apache.geode.internal.ClassBuilder) File(java.io.File) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 79 with PartitionAttributes

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;
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) ExtensionPoint(org.apache.geode.internal.cache.extension.ExtensionPoint) PartitionAttributes(org.apache.geode.cache.PartitionAttributes)

Example 80 with PartitionAttributes

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);
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) Host(org.apache.geode.test.dunit.Host) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Aggregations

PartitionAttributes (org.apache.geode.cache.PartitionAttributes)129 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)117 AttributesFactory (org.apache.geode.cache.AttributesFactory)107 Region (org.apache.geode.cache.Region)82 Test (org.junit.Test)67 Cache (org.apache.geode.cache.Cache)66 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)61 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)49 Host (org.apache.geode.test.dunit.Host)48 VM (org.apache.geode.test.dunit.VM)48 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)47 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)38 RegionAttributes (org.apache.geode.cache.RegionAttributes)28 CacheException (org.apache.geode.cache.CacheException)26 LocalRegion (org.apache.geode.internal.cache.LocalRegion)26 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)21 BucketRegion (org.apache.geode.internal.cache.BucketRegion)19 FixedPartitionAttributes (org.apache.geode.cache.FixedPartitionAttributes)18 RebalanceResults (org.apache.geode.cache.control.RebalanceResults)16 HashSet (java.util.HashSet)15