Search in sources :

Example 81 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.

the class MemoryThresholdsDUnitTest method prRemotePutRejection.

private void prRemotePutRejection(boolean cacheClose, boolean localDestroy, final boolean useTx) throws Exception {
    final Host host = Host.getHost(0);
    final VM accessor = host.getVM(0);
    final VM server1 = host.getVM(1);
    final VM server2 = host.getVM(2);
    final VM server3 = host.getVM(3);
    final String regionName = "testPrRejection";
    final int redundancy = 1;
    final ServerPorts ports1 = startCacheServer(server1, 80f, 90f, regionName, true, /* createPR */
    false, /* notifyBySubscription */
    redundancy);
    ServerPorts ports2 = startCacheServer(server2, 80f, 90f, regionName, true, /* createPR */
    false, /* notifyBySubscription */
    redundancy);
    ServerPorts ports3 = startCacheServer(server3, 80f, 90f, regionName, true, /* createPR */
    false, /* notifyBySubscription */
    redundancy);
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            getSystem(getServerProperties());
            getCache();
            AttributesFactory factory = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(redundancy);
            paf.setLocalMaxMemory(0);
            paf.setTotalNumBuckets(11);
            factory.setPartitionAttributes(paf.create());
            createRegion(regionName, factory.create());
            return null;
        }
    });
    doPuts(accessor, regionName, false, false);
    final Range r1 = Range.DEFAULT;
    doPutAlls(accessor, regionName, false, false, r1);
    SerializableCallable getMyId = new SerializableCallable() {

        public Object call() throws Exception {
            return ((GemFireCacheImpl) getCache()).getMyId();
        }
    };
    final DistributedMember server1Id = (DistributedMember) server1.invoke(getMyId);
    setUsageAboveCriticalThreshold(server1);
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            final PartitionedRegion pr = (PartitionedRegion) getRootRegion().getSubregion(regionName);
            final String regionPath = getRootRegion().getSubregion(regionName).getFullPath();
            // server1 is sick, look for a key on server1, and attempt put again
            WaitCriterion wc = new WaitCriterion() {

                public String description() {
                    return "remote bucket not marked sick";
                }

                public boolean done() {
                    boolean keyFoundOnSickMember = false;
                    boolean caughtException = false;
                    for (int i = 0; i < 20; i++) {
                        Integer key = Integer.valueOf(i);
                        int hKey = PartitionedRegionHelper.getHashKey(pr, null, key, null, null);
                        Set<InternalDistributedMember> owners = pr.getRegionAdvisor().getBucketOwners(hKey);
                        if (owners.contains(server1Id)) {
                            keyFoundOnSickMember = true;
                            try {
                                if (useTx)
                                    getCache().getCacheTransactionManager().begin();
                                pr.getCache().getLogger().fine("SWAP:putting in tx:" + useTx);
                                pr.put(key, "value");
                                if (useTx)
                                    getCache().getCacheTransactionManager().commit();
                            } catch (LowMemoryException ex) {
                                caughtException = true;
                                if (useTx)
                                    getCache().getCacheTransactionManager().rollback();
                            }
                        } else {
                            // puts on healthy member should continue
                            pr.put(key, "value");
                        }
                    }
                    return keyFoundOnSickMember && caughtException;
                }
            };
            Wait.waitForCriterion(wc, 30000, 10, true);
            return null;
        }
    });
    {
        Range r2 = new Range(r1, r1.width() + 1);
        doPutAlls(accessor, regionName, false, true, r2);
    }
    if (localDestroy) {
        // local destroy the region on sick member
        server1.invoke(new SerializableCallable("local destroy sick member") {

            public Object call() throws Exception {
                Region r = getRootRegion().getSubregion(regionName);
                LogWriterUtils.getLogWriter().info("PRLocalDestroy");
                r.localDestroyRegion();
                return null;
            }
        });
    } else if (cacheClose) {
        // close cache on sick member
        server1.invoke(new SerializableCallable("close cache sick member") {

            public Object call() throws Exception {
                getCache().close();
                return null;
            }
        });
    } else {
        setUsageBelowEviction(server1);
    }
    // do put all in a loop to allow distribution of message
    accessor.invoke(new SerializableCallable("Put in a loop") {

        public Object call() throws Exception {
            final Region r = getRootRegion().getSubregion(regionName);
            WaitCriterion wc = new WaitCriterion() {

                public String description() {
                    return "pr should have gone un-critical";
                }

                public boolean done() {
                    boolean done = true;
                    for (int i = 0; i < 20; i++) {
                        try {
                            r.put(i, "value");
                        } catch (LowMemoryException e) {
                            // expected
                            done = false;
                        }
                    }
                    return done;
                }
            };
            Wait.waitForCriterion(wc, 30000, 10, true);
            return null;
        }
    });
    doPutAlls(accessor, regionName, false, false, r1);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Host(org.apache.geode.test.dunit.Host) IgnoredException(org.apache.geode.test.dunit.IgnoredException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) LowMemoryException(org.apache.geode.cache.LowMemoryException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) CacheException(org.apache.geode.cache.CacheException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) LowMemoryException(org.apache.geode.cache.LowMemoryException)

Example 82 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.

the class MultiVMRegionTestCase method versionTestConcurrentEvents.

/**
   * This tests the concurrency versioning system to ensure that event conflation happens correctly
   * and that the statistic is being updated properly
   */
public void versionTestConcurrentEvents() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    // create replicated regions in VM 0 and 1, then perform concurrent ops
    // on the same key while creating the region in VM2. Afterward make
    // sure that all three regions are consistent
    final String name = this.getUniqueName() + "-CC";
    SerializableRunnable createRegion = new SerializableRunnable("Create Region") {

        @Override
        public void run() {
            try {
                RegionFactory f = getCache().createRegionFactory(getRegionAttributes());
                CCRegion = (LocalRegion) f.create(name);
            } catch (CacheException ex) {
                fail("While creating region", ex);
            }
        }
    };
    vm0.invoke(createRegion);
    vm1.invoke(createRegion);
    SerializableRunnable performOps = new SerializableRunnable("perform concurrent ops") {

        @Override
        public void run() {
            try {
                doOpsLoop(5000, false);
                long events = CCRegion.getCachePerfStats().getConflatedEventsCount();
                if (!CCRegion.getScope().isGlobal()) {
                    assertTrue("expected some event conflation", events > 0);
                }
            } catch (CacheException e) {
                fail("while performing concurrent operations", e);
            }
        // } catch (InterruptedException e) {
        // fail("someone interrupted my sleep");
        // }
        }
    };
    AsyncInvocation a0 = vm0.invokeAsync(performOps);
    AsyncInvocation a1 = vm1.invokeAsync(performOps);
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        fail("sleep was interrupted");
    }
    vm2.invoke(createRegion);
    boolean a0failed = waitForAsyncProcessing(a0, "expected some event conflation");
    boolean a1failed = waitForAsyncProcessing(a1, "expected some event conflation");
    if (a0failed && a1failed) {
        fail("neither member saw event conflation - check stats for " + name);
    }
    // check consistency of the regions
    Map r0Contents = (Map) vm0.invoke(() -> this.getCCRegionContents());
    Map r1Contents = (Map) vm1.invoke(() -> this.getCCRegionContents());
    Map r2Contents = (Map) vm2.invoke(() -> this.getCCRegionContents());
    for (int i = 0; i < 10; i++) {
        String key = "cckey" + i;
        assertEquals("region contents are not consistent for " + key, r0Contents.get(key), r1Contents.get(key));
        assertEquals("region contents are not consistent for " + key, r1Contents.get(key), r2Contents.get(key));
        for (int subi = 1; subi < 3; subi++) {
            String subkey = key + "-" + subi;
            if (r0Contents.containsKey(subkey)) {
                assertEquals("region contents are not consistent for " + subkey, r0Contents.get(subkey), r1Contents.get(subkey));
                assertEquals("region contents are not consistent for " + subkey, r1Contents.get(subkey), r2Contents.get(subkey));
            } else {
                assertTrue(!r1Contents.containsKey(subkey));
            }
        }
    }
    if (!getRegionAttributes().getScope().isDistributedNoAck()) {
        // no-ack doesn't support deltas
        vm0.invoke(() -> this.clearCCRegion());
        performOps = new SerializableRunnable("perform concurrent delta ops") {

            @Override
            public void run() {
                try {
                    long stopTime = System.currentTimeMillis() + 5000;
                    Random ran = new Random(System.currentTimeMillis());
                    while (System.currentTimeMillis() < stopTime) {
                        for (int i = 0; i < 10; i++) {
                            CCRegion.put("cckey" + i, new DeltaValue("ccvalue" + ran.nextInt()));
                        }
                    }
                    long events = CCRegion.getCachePerfStats().getDeltaFailedUpdates();
                    assertTrue("expected some failed deltas", events > 0);
                } catch (CacheException e) {
                    fail("while performing concurrent operations", e);
                }
            }
        };
        a0 = vm0.invokeAsync(performOps);
        a1 = vm1.invokeAsync(performOps);
        a0failed = waitForAsyncProcessing(a0, "expected some failed deltas");
        a1failed = waitForAsyncProcessing(a1, "expected some failed deltas");
        if (a0failed && a1failed) {
            fail("neither member saw failed deltas - check stats for " + name);
        }
        // check consistency of the regions
        r0Contents = (Map) vm0.invoke(() -> this.getCCRegionContents());
        r1Contents = (Map) vm1.invoke(() -> this.getCCRegionContents());
        r2Contents = (Map) vm2.invoke(() -> this.getCCRegionContents());
        for (int i = 0; i < 10; i++) {
            String key = "cckey" + i;
            assertEquals("region contents are not consistent", r0Contents.get(key), r1Contents.get(key));
            assertEquals("region contents are not consistent", r1Contents.get(key), r2Contents.get(key));
            for (int subi = 1; subi < 3; subi++) {
                String subkey = key + "-" + subi;
                if (r0Contents.containsKey(subkey)) {
                    assertEquals("region contents are not consistent", r0Contents.get(subkey), r1Contents.get(subkey));
                    assertEquals("region contents are not consistent", r1Contents.get(subkey), r2Contents.get(subkey));
                } else {
                    assertTrue(!r1Contents.containsKey(subkey));
                }
            }
        }
        // The region version vectors should now all be consistent with the version stamps in the
        // entries.
        InternalDistributedMember vm0Id = (InternalDistributedMember) vm0.invoke(() -> this.getMemberId());
        InternalDistributedMember vm1Id = (InternalDistributedMember) vm1.invoke(() -> this.getMemberId());
        InternalDistributedMember vm2Id = (InternalDistributedMember) vm2.invoke(() -> this.getMemberId());
        long start = System.currentTimeMillis();
        RegionVersionVector vm0vv = getVersionVector(vm0);
        long end = System.currentTimeMillis();
        org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("version vector transmission took " + (end - start) + " ms");
        org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("vm0 vector = " + vm0vv);
        RegionVersionVector vm1vv = getVersionVector(vm1);
        org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("vm1 vector = " + vm1vv);
        RegionVersionVector vm2vv = getVersionVector(vm2);
        org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("vm2 vector = " + vm2vv);
        Map<String, VersionTag> vm0Versions = (Map<String, VersionTag>) vm0.invoke(() -> this.getCCRegionVersions());
        Map<String, VersionTag> vm1Versions = (Map<String, VersionTag>) vm1.invoke(() -> this.getCCRegionVersions());
        Map<String, VersionTag> vm2Versions = (Map<String, VersionTag>) vm2.invoke(() -> this.getCCRegionVersions());
        for (Map.Entry<String, VersionTag> entry : vm0Versions.entrySet()) {
            VersionTag tag = entry.getValue();
            tag.replaceNullIDs(vm0Id);
            assertTrue(vm0Id + " should contain " + tag, vm0vv.contains(tag.getMemberID(), tag.getRegionVersion()));
            assertTrue(vm1Id + " should contain " + tag, vm1vv.contains(tag.getMemberID(), tag.getRegionVersion()));
            assertTrue(vm2Id + " should contain " + tag, vm2vv.contains(tag.getMemberID(), tag.getRegionVersion()));
        }
        for (Map.Entry<String, VersionTag> entry : vm1Versions.entrySet()) {
            VersionTag tag = entry.getValue();
            tag.replaceNullIDs(vm1Id);
            assertTrue(vm0Id + " should contain " + tag, vm0vv.contains(tag.getMemberID(), tag.getRegionVersion()));
            assertTrue(vm1Id + " should contain " + tag, vm1vv.contains(tag.getMemberID(), tag.getRegionVersion()));
            assertTrue(vm2Id + " should contain " + tag, vm2vv.contains(tag.getMemberID(), tag.getRegionVersion()));
        }
        for (Map.Entry<String, VersionTag> entry : vm2Versions.entrySet()) {
            VersionTag tag = entry.getValue();
            tag.replaceNullIDs(vm2Id);
            assertTrue(vm0Id + " should contain " + tag, vm0vv.contains(tag.getMemberID(), tag.getRegionVersion()));
            assertTrue(vm1Id + " should contain " + tag, vm1vv.contains(tag.getMemberID(), tag.getRegionVersion()));
            assertTrue(vm2Id + " should contain " + tag, vm2vv.contains(tag.getMemberID(), tag.getRegionVersion()));
        }
    }
}
Also used : CacheException(org.apache.geode.cache.CacheException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) RegionFactory(org.apache.geode.cache.RegionFactory) Random(java.util.Random) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) VM(org.apache.geode.test.dunit.VM) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) Map(java.util.Map) HashMap(java.util.HashMap)

Example 83 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.

the class RoleDUnitTest method testDuplicateRoleNames.

/**
   * Tests that specifying duplicate role names results in just one Role.
   */
@Test
public void testDuplicateRoleNames() {
    final String rolesProp = "A,A";
    Properties config = new Properties();
    config.setProperty(MCAST_PORT, "0");
    config.setProperty(LOCATORS, "");
    config.setProperty(ROLES, rolesProp);
    distributionProperties = config;
    InternalDistributedSystem system = getSystem();
    try {
        DM dm = system.getDistributionManager();
        InternalDistributedMember member = dm.getDistributionManagerId();
        Set roles = member.getRoles();
        assertEquals(1, roles.size());
        Role role = (Role) roles.iterator().next();
        assertEquals(true, role.isPresent());
        assertEquals(1, role.getCount());
    } finally {
        system.disconnect();
    }
}
Also used : InternalRole(org.apache.geode.distributed.internal.membership.InternalRole) Set(java.util.Set) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DM(org.apache.geode.distributed.internal.DM) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 84 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.

the class RoleDUnitTest method testRolesInLonerVM.

/**
   * Tests usage of Roles in a Loner vm.
   */
@Test
public void testRolesInLonerVM() {
    final String rolesProp = "A,B,C,D,E,F,G";
    final String[] rolesArray = new String[] { "A", "B", "C", "D", "E", "F", "G" };
    distributionProperties = new Properties();
    distributionProperties.setProperty(MCAST_PORT, "0");
    distributionProperties.setProperty(LOCATORS, "");
    distributionProperties.setProperty(ROLES, rolesProp);
    InternalDistributedSystem system = getSystem(distributionProperties);
    try {
        DM dm = system.getDistributionManager();
        Set allRoles = dm.getAllRoles();
        assertEquals(rolesArray.length, allRoles.size());
        InternalDistributedMember member = dm.getDistributionManagerId();
        Set roles = member.getRoles();
        assertEquals(rolesArray.length, roles.size());
        Role roleA = InternalRole.getRole("roleA");
        assertEquals(false, roleA.isPresent());
        assertEquals(0, roleA.getCount());
        for (Iterator iter = roles.iterator(); iter.hasNext(); ) {
            Role role = (Role) iter.next();
            assertEquals(true, role.isPresent());
            assertEquals(1, role.getCount());
        }
    } finally {
        system.disconnect();
    }
}
Also used : InternalRole(org.apache.geode.distributed.internal.membership.InternalRole) Set(java.util.Set) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Iterator(java.util.Iterator) DM(org.apache.geode.distributed.internal.DM) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 85 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.

the class GMSJoinLeaveJUnitTest method testBecomeCoordinatorThroughViewChange.

@Test
public void testBecomeCoordinatorThroughViewChange() throws Exception {
    initMocks();
    prepareAndInstallView(mockMembers[0], createMemberList(mockMembers[0], gmsJoinLeaveMemberId));
    NetView oldView = gmsJoinLeave.getView();
    oldView.add(gmsJoinLeaveMemberId);
    NetView view = new NetView(oldView, oldView.getViewId() + 1);
    InternalDistributedMember creator = view.getCreator();
    view.remove(creator);
    InstallViewMessage msg = getInstallViewMessage(view, creator, false);
    msg.setSender(creator);
    gmsJoinLeave.processMessage(msg);
    assertTrue("Expected it to become coordinator", gmsJoinLeave.isCoordinator());
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) NetView(org.apache.geode.distributed.internal.membership.NetView) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)516 Test (org.junit.Test)162 HashSet (java.util.HashSet)124 Set (java.util.Set)77 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)63 NetView (org.apache.geode.distributed.internal.membership.NetView)60 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)56 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)55 ArrayList (java.util.ArrayList)54 DistributedMember (org.apache.geode.distributed.DistributedMember)49 UnitTest (org.apache.geode.test.junit.categories.UnitTest)49 HashMap (java.util.HashMap)46 IOException (java.io.IOException)36 Iterator (java.util.Iterator)34 PartitionedRegionLoadModel (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel)34 CompositeDirector (org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector)33 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)32 Map (java.util.Map)29 CancelException (org.apache.geode.CancelException)29 DM (org.apache.geode.distributed.internal.DM)29