Search in sources :

Example 51 with PartitionAttributes

use of org.apache.geode.cache.PartitionAttributes in project geode by apache.

the class LDSRoutingObject method createPR.

public static void createPR(String partitionedRegionName, Integer redundancy, Integer localMaxMemory, Integer totalNumBuckets, String colocatedWith) {
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    PartitionAttributes prAttr = paf.setRedundantCopies(redundancy.intValue()).setLocalMaxMemory(localMaxMemory.intValue()).setTotalNumBuckets(totalNumBuckets.intValue()).setColocatedWith(colocatedWith).setPartitionResolver(new LDSPartitionResolver()).create();
    AttributesFactory attr = new AttributesFactory();
    attr.setPartitionAttributes(prAttr);
    assertNotNull(basicGetCache());
    if (partitionedRegionName.equals("CustomerPR")) {
        customerPR = basicGetCache().createRegion(partitionedRegionName, attr.create());
        assertNotNull(customerPR);
        LogWriterUtils.getLogWriter().info("Partitioned Region " + partitionedRegionName + " created Successfully :" + customerPR);
    }
    if (partitionedRegionName.equals("OrderPR")) {
        orderPR = basicGetCache().createRegion(partitionedRegionName, attr.create());
        assertNotNull(orderPR);
        LogWriterUtils.getLogWriter().info("Partitioned Region " + partitionedRegionName + " created Successfully :" + orderPR);
    }
    if (partitionedRegionName.equals("ShipmentPR")) {
        shipmentPR = basicGetCache().createRegion(partitionedRegionName, attr.create());
        assertNotNull(shipmentPR);
        LogWriterUtils.getLogWriter().info("Partitioned Region " + partitionedRegionName + " created Successfully :" + shipmentPR);
    }
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionAttributes(org.apache.geode.cache.PartitionAttributes)

Example 52 with PartitionAttributes

use of org.apache.geode.cache.PartitionAttributes in project geode by apache.

the class ParallelQueueRemovalMessageJUnitTest method createBucketRegionQueue.

private void createBucketRegionQueue() {
    // Create InternalRegionArguments
    InternalRegionArguments ira = new InternalRegionArguments();
    ira.setPartitionedRegion(this.queueRegion);
    ira.setPartitionedRegionBucketRedundancy(1);
    BucketAdvisor ba = mock(BucketAdvisor.class);
    ira.setBucketAdvisor(ba);
    InternalRegionArguments pbrIra = new InternalRegionArguments();
    RegionAdvisor ra = mock(RegionAdvisor.class);
    when(ra.getPartitionedRegion()).thenReturn(this.queueRegion);
    pbrIra.setPartitionedRegionAdvisor(ra);
    PartitionAttributes pa = mock(PartitionAttributes.class);
    when(this.queueRegion.getPartitionAttributes()).thenReturn(pa);
    when(this.queueRegion.getBucketName(eq(BUCKET_ID))).thenAnswer(new Answer<String>() {

        @Override
        public String answer(final InvocationOnMock invocation) throws Throwable {
            return PartitionedRegionHelper.getBucketName(queueRegion.getFullPath(), BUCKET_ID);
        }
    });
    when(this.queueRegion.getDataPolicy()).thenReturn(DataPolicy.PARTITION);
    when(pa.getColocatedWith()).thenReturn(null);
    // classes cannot be mocked
    ProxyBucketRegion pbr = new ProxyBucketRegion(BUCKET_ID, this.queueRegion, pbrIra);
    when(ba.getProxyBucketRegion()).thenReturn(pbr);
    // Create RegionAttributes
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setDataPolicy(DataPolicy.REPLICATE);
    factory.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(100, null, EvictionAction.OVERFLOW_TO_DISK));
    RegionAttributes attributes = factory.create();
    // Create BucketRegionQueue
    BucketRegionQueue realBucketRegionQueue = new BucketRegionQueue(this.queueRegion.getBucketName(BUCKET_ID), attributes, this.rootRegion, this.cache, ira);
    this.bucketRegionQueue = spy(realBucketRegionQueue);
    // (this.queueRegion.getBucketName(BUCKET_ID), attributes, this.rootRegion, this.cache, ira);
    EntryEventImpl entryEvent = EntryEventImpl.create(this.bucketRegionQueue, Operation.DESTROY, mock(EventID.class), "value", null, false, mock(DistributedMember.class));
    doReturn(entryEvent).when(this.bucketRegionQueue).newDestroyEntryEvent(any(), any());
    // when(this.bucketRegionQueue.newDestroyEntryEvent(any(), any())).thenReturn();
    this.bucketRegionQueueHelper = new BucketRegionQueueHelper(this.cache, this.queueRegion, this.bucketRegionQueue);
}
Also used : RegionAdvisor(org.apache.geode.internal.cache.partitioned.RegionAdvisor) RegionAttributes(org.apache.geode.cache.RegionAttributes) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) BucketRegionQueueHelper(org.apache.geode.internal.cache.BucketRegionQueueHelper) AttributesFactory(org.apache.geode.cache.AttributesFactory) BucketRegionQueue(org.apache.geode.internal.cache.BucketRegionQueue) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ProxyBucketRegion(org.apache.geode.internal.cache.ProxyBucketRegion) DistributedMember(org.apache.geode.distributed.DistributedMember) EventID(org.apache.geode.internal.cache.EventID) BucketAdvisor(org.apache.geode.internal.cache.BucketAdvisor)

Example 53 with PartitionAttributes

use of org.apache.geode.cache.PartitionAttributes in project geode by apache.

the class DiskStoreCommandsDUnitTest method testMissingDiskStoreCommandWithColocation.

@Test
public void testMissingDiskStoreCommandWithColocation() {
    final String regionName = "testShowPersistentRecoveryFailuresRegion";
    final String childName = "childRegion";
    setUpJmxManagerOnVm0ThenConnect(null);
    final VM vm0 = Host.getHost(0).getVM(0);
    final VM vm1 = Host.getHost(0).getVM(1);
    final String vm1Name = "VM" + vm1.getPid();
    final String diskStoreName = "DiskStoreCommandsDUnitTest";
    // Default setup creates a cache in the Manager, now create a cache in VM1
    vm1.invoke(new SerializableRunnable() {

        public void run() {
            Properties localProps = new Properties();
            localProps.setProperty(NAME, vm1Name);
            getSystem(localProps);
            Cache cache = getCache();
        }
    });
    // Create a disk store and region in the Manager (VM0) and VM1 VMs
    for (final VM vm : (new VM[] { vm0, vm1 })) {
        final String vmName = "VM" + vm.getPid();
        vm.invoke(new SerializableRunnable() {

            public void run() {
                Cache cache = getCache();
                File diskStoreDirFile = new File(diskStoreName + vm.getPid());
                diskStoreDirFile.mkdirs();
                DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
                diskStoreFactory.setDiskDirs(new File[] { diskStoreDirFile });
                diskStoreFactory.setMaxOplogSize(1);
                diskStoreFactory.setAllowForceCompaction(true);
                diskStoreFactory.setAutoCompact(false);
                diskStoreFactory.create(regionName);
                diskStoreFactory.create(childName);
                RegionFactory regionFactory = cache.createRegionFactory();
                regionFactory.setDiskStoreName(regionName);
                regionFactory.setDiskSynchronous(true);
                regionFactory.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
                regionFactory.create(regionName);
                PartitionAttributes pa = new PartitionAttributesFactory().setColocatedWith(regionName).create();
                RegionFactory childRegionFactory = cache.createRegionFactory();
                childRegionFactory.setPartitionAttributes(pa);
                childRegionFactory.setDiskStoreName(childName);
                childRegionFactory.setDiskSynchronous(true);
                childRegionFactory.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
                childRegionFactory.create(childName);
            }
        });
    }
    // Add data to the region
    vm0.invoke(new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion(regionName);
            region.put("A", "a");
            region.put("B", "b");
        }
    });
    // Make sure that everything thus far is okay and there are no missing disk stores
    CommandResult cmdResult = executeCommand(CliStrings.SHOW_MISSING_DISK_STORE);
    System.out.println("command result=\n" + commandResultToString(cmdResult));
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    assertTrue(cmdResult.toString(), commandResultToString(cmdResult).contains("No missing disk store found"));
    // Close the regions in the Manager (VM0) VM
    vm0.invoke(new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion(childName);
            region.close();
            region = cache.getRegion(regionName);
            region.close();
        }
    });
    // Add data to VM1 and then close the region
    vm1.invoke(new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            Region childRegion = cache.getRegion(childName);
            PartitionedRegion parentRegion = (PartitionedRegion) (cache.getRegion(regionName));
            try {
                parentRegion.put("A", "C");
            } catch (Exception e) {
            // Ignore any exception on the put
            }
            childRegion.close();
            parentRegion.close();
        }
    });
    SerializableRunnable restartParentRegion = new SerializableRunnable("Restart parent region on") {

        public void run() {
            Cache cache = getCache();
            RegionFactory regionFactory = cache.createRegionFactory();
            regionFactory.setDiskStoreName(regionName);
            regionFactory.setDiskSynchronous(true);
            regionFactory.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
            try {
                regionFactory.create(regionName);
            } catch (Exception e) {
            // okay to ignore
            }
        }
    };
    SerializableRunnable restartChildRegion = new SerializableRunnable("Restart child region") {

        public void run() {
            Cache cache = getCache();
            PartitionAttributes pa = new PartitionAttributesFactory().setColocatedWith(regionName).create();
            RegionFactory regionFactory = cache.createRegionFactory();
            regionFactory.setPartitionAttributes(pa);
            regionFactory.setDiskStoreName(childName);
            regionFactory.setDiskSynchronous(true);
            regionFactory.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
            try {
                regionFactory.create(childName);
            } catch (Exception e) {
                // okay to ignore
                e.printStackTrace();
            }
        }
    };
    // Add the region back to the Manager (VM0) VM
    AsyncInvocation async0 = vm0.invokeAsync(restartParentRegion);
    AsyncInvocation async1 = vm1.invokeAsync(restartParentRegion);
    // Wait for the region in the Manager (VM0) to come online
    vm0.invoke(new SerializableRunnable("WaitForRegionInVm0") {

        public void run() {
            WaitCriterion waitCriterion = new WaitCriterion() {

                public boolean done() {
                    Cache cache = getCache();
                    PersistentMemberManager memberManager = ((GemFireCacheImpl) cache).getPersistentMemberManager();
                    return !memberManager.getWaitingRegions().isEmpty();
                }

                public String description() {
                    return "Waiting for another persistent member to come online";
                }
            };
            try {
                waitForCriterion(waitCriterion, 5000, 100, true);
            } catch (AssertionError ae) {
            // Ignore. waitForCriterion is expected to timeout in this test
            }
        }
    });
    // Validate that there is a missing disk store on VM1
    try {
        cmdResult = executeCommand(CliStrings.SHOW_MISSING_DISK_STORE);
        assertNotNull("Expect command result != null", cmdResult);
        assertEquals(Result.Status.OK, cmdResult.getStatus());
        String stringResult = commandResultToString(cmdResult);
        System.out.println("command result=\n" + stringResult);
        // Expect 2 result sections with header lines and 4 information lines in the first section
        assertEquals(6, countLinesInString(stringResult, false));
        assertTrue(stringContainsLine(stringResult, "Host.*Distributed Member.*Parent Region.*Missing Colocated Region"));
        assertTrue(stringContainsLine(stringResult, ".*" + regionName + ".*" + childName));
        AsyncInvocation async0b = vm0.invokeAsync(restartChildRegion);
        try {
            async0b.get(5000, TimeUnit.MILLISECONDS);
        } catch (Exception e) {
        // Expected timeout - Region recovery is still waiting on vm1 child region and disk-store to
        // come online
        }
        cmdResult = executeCommand(CliStrings.SHOW_MISSING_DISK_STORE);
        assertNotNull("Expect command result != null", cmdResult);
        assertEquals(Result.Status.OK, cmdResult.getStatus());
        stringResult = commandResultToString(cmdResult);
        System.out.println("command result=\n" + stringResult);
        // Extract the id from the returned missing disk store
        String line = getLineFromString(stringResult, 4);
        assertFalse(line.contains("---------"));
        StringTokenizer resultTokenizer = new StringTokenizer(line);
        String id = resultTokenizer.nextToken();
        AsyncInvocation async1b = vm1.invokeAsync(restartChildRegion);
        try {
            async1b.get(5000, TimeUnit.MILLISECONDS);
        } catch (Exception e) {
            e.printStackTrace();
        }
        cmdResult = executeCommand(CliStrings.SHOW_MISSING_DISK_STORE);
        assertNotNull("Expect command result != null", cmdResult);
        assertEquals(Result.Status.OK, cmdResult.getStatus());
        stringResult = commandResultToString(cmdResult);
        System.out.println("command result=\n" + stringResult);
    } finally {
        // Verify that the invokeAsync thread terminated
        try {
            async0.get(10000, TimeUnit.MILLISECONDS);
            async1.get(10000, TimeUnit.MILLISECONDS);
        } catch (Exception e) {
            fail("Unexpected timeout waitiong for invokeAsync threads to terminate: " + e.getMessage());
        }
    }
    // Do our own cleanup so that the disk store directories can be removed
    super.destroyDefaultSetup();
    for (final VM vm : (new VM[] { vm0, vm1 })) {
        final String vmName = "VM" + vm.getPid();
        vm.invoke(new SerializableRunnable() {

            public void run() {
                try {
                    FileUtils.deleteDirectory((new File(diskStoreName + vm.getPid())));
                } catch (IOException iex) {
                // There's nothing else we can do
                }
            }
        });
    }
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) IOException(java.io.IOException) Properties(java.util.Properties) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PersistentMemberManager(org.apache.geode.internal.cache.persistence.PersistentMemberManager) StringTokenizer(java.util.StringTokenizer) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) RegionFactory(org.apache.geode.cache.RegionFactory) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) VM(org.apache.geode.test.dunit.VM) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) File(java.io.File) Cache(org.apache.geode.cache.Cache) InternalCache(org.apache.geode.internal.cache.InternalCache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 54 with PartitionAttributes

use of org.apache.geode.cache.PartitionAttributes 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);
}
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) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) CacheException(org.apache.geode.cache.CacheException) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 55 with PartitionAttributes

use of org.apache.geode.cache.PartitionAttributes in project geode by apache.

the class Bug40632DUnitTest method testLocalDestroyTimeToLive.

@Test
public void testLocalDestroyTimeToLive() throws Exception {
    Cache cache = getCache();
    AttributesFactory attr = new AttributesFactory();
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    paf.setRedundantCopies(1);
    paf.setRecoveryDelay(-1);
    paf.setStartupRecoveryDelay(-1);
    PartitionAttributes prAttr = paf.create();
    attr.setStatisticsEnabled(true);
    attr.setEntryTimeToLive(new ExpirationAttributes(1000, ExpirationAction.LOCAL_DESTROY));
    attr.setPartitionAttributes(prAttr);
    try {
        cache.createRegion("region1", attr.create());
        fail("We should not have been able to create the region");
    } catch (IllegalStateException expected) {
    }
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

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