Search in sources :

Example 11 with DistributionManager

use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.

the class PersistentRVVRecoveryDUnitTest method testSkipConflictChecksForConcurrentOps.

/**
   * Test that we skip conflict checks with entries that are on disk compared to entries that come
   * in as part of a concurrent operation
   */
@Test
public void testSkipConflictChecksForConcurrentOps() throws Throwable {
    Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    // Create the region in few members to test recovery
    createPersistentRegion(vm0);
    createPersistentRegion(vm1);
    // Create an update some entries in vm0 and vm1.
    createData(vm0, 0, 1, "value1");
    createData(vm0, 0, 1, "value2");
    createData(vm0, 0, 1, "value2");
    closeCache(vm1);
    // Update the keys in vm0 until the entry version rolls over.
    // This means that if we did a conflict check, vm0's key will have
    // a lower entry version than vm1, which would cause us to prefer vm1's
    // value
    SerializableRunnable createData = new SerializableRunnable("rollEntryVersion") {

        public void run() {
            Cache cache = getCache();
            LocalRegion region = (LocalRegion) cache.getRegion(REGION_NAME);
            region.put(0, "value3");
            RegionEntry entry = region.getRegionEntry(0);
            entry = region.getRegionEntry(0);
            // Sneak in and change the version number for an entry to generate
            // a conflict.
            VersionTag tag = entry.getVersionStamp().asVersionTag();
            tag.setEntryVersion(tag.getEntryVersion() - 2);
            entry.getVersionStamp().setVersions(tag);
        }
    };
    vm0.invoke(createData);
    // Add an observer to vm0 which will perform a concurrent operation during
    // the GII. If we do a conflict check, this operation will be rejected
    // because it will have a lower entry version that what vm1 recovered from
    // disk
    vm0.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage msg) {
                    if (msg instanceof InitialImageOperation.RequestImageMessage) {
                        if (((InitialImageOperation.RequestImageMessage) msg).regionPath.contains(REGION_NAME)) {
                            createData(vm0, 0, 1, "value4");
                            DistributionMessageObserver.setInstance(null);
                        }
                    }
                }
            });
        }
    });
    // Create vm1, doing a GII
    createPersistentRegion(vm1);
    // If we did a conflict check, this would be value2
    checkData(vm0, 0, 1, "value4");
    checkData(vm1, 0, 1, "value4");
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) RegionEntry(org.apache.geode.internal.cache.RegionEntry) InitialImageOperation(org.apache.geode.internal.cache.InitialImageOperation) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 12 with DistributionManager

use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.

the class HostedLocatorsDUnitTest method testGetAllHostedLocatorsUsingPortZero.

@Test
public void testGetAllHostedLocatorsUsingPortZero() throws Exception {
    final InternalDistributedSystem system = getSystem();
    final String dunitLocator = system.getConfig().getLocators();
    assertNotNull(dunitLocator);
    assertFalse(dunitLocator.isEmpty());
    // This will eventually contain the ports used by locators
    final int[] ports = new int[] { 0, 0, 0, 0 };
    final String uniqueName = getUniqueName();
    for (int i = 0; i < 4; i++) {
        final int whichvm = i;
        Integer port = (Integer) Host.getHost(0).getVM(whichvm).invoke(new SerializableCallable() {

            @Override
            public Object call() throws Exception {
                try {
                    System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "locators", dunitLocator);
                    System.setProperty(DistributionConfig.GEMFIRE_PREFIX + MCAST_PORT, "0");
                    final String name = uniqueName + "-" + whichvm;
                    final File subdir = new File(name);
                    subdir.mkdir();
                    assertTrue(subdir.exists() && subdir.isDirectory());
                    final Builder builder = new Builder().setMemberName(name).setPort(ports[whichvm]).setRedirectOutput(true).setWorkingDirectory(name);
                    launcher = builder.build();
                    assertEquals(Status.ONLINE, launcher.start().getStatus());
                    waitForLocatorToStart(launcher, TIMEOUT_MILLISECONDS, 10, true);
                    return launcher.getPort();
                } finally {
                    System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + "locators");
                    System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + MCAST_PORT);
                }
            }
        });
        ports[i] = port;
    }
    final String host = SocketCreator.getLocalHost().getHostAddress();
    final Set<String> locators = new HashSet<String>();
    locators.add(host + "[" + dunitLocator.substring(dunitLocator.indexOf("[") + 1, dunitLocator.indexOf("]")) + "]");
    for (int port : ports) {
        locators.add(host + "[" + port + "]");
    }
    // validation within non-locator
    final DistributionManager dm = (DistributionManager) system.getDistributionManager();
    final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
    assertEquals(5, locatorIds.size());
    final Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
    assertTrue(!hostedLocators.isEmpty());
    assertEquals(5, hostedLocators.size());
    for (InternalDistributedMember member : hostedLocators.keySet()) {
        assertEquals(1, hostedLocators.get(member).size());
        final String hostedLocator = hostedLocators.get(member).iterator().next();
        assertTrue(locators + " does not contain " + hostedLocator, locators.contains(hostedLocator));
    }
    // validate fix for #46324
    for (int whichvm = 0; whichvm < 4; whichvm++) {
        Host.getHost(0).getVM(whichvm).invoke(new SerializableRunnable() {

            @Override
            public void run() {
                final DistributionManager dm = (DistributionManager) InternalDistributedSystem.getAnyInstance().getDistributionManager();
                final InternalDistributedMember self = dm.getDistributionManagerId();
                final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
                assertTrue(locatorIds.contains(self));
                final Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
                assertTrue("hit bug #46324: " + hostedLocators + " is missing " + InternalLocator.getLocatorStrings() + " for " + self, hostedLocators.containsKey(self));
            }
        });
    }
    // validation with locators
    for (int whichvm = 0; whichvm < 4; whichvm++) {
        Host.getHost(0).getVM(whichvm).invoke(new SerializableRunnable() {

            @Override
            public void run() {
                final DistributionManager dm = (DistributionManager) InternalDistributedSystem.getAnyInstance().getDistributionManager();
                final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
                assertEquals(5, locatorIds.size());
                final Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
                assertTrue(!hostedLocators.isEmpty());
                assertEquals(5, hostedLocators.size());
                for (InternalDistributedMember member : hostedLocators.keySet()) {
                    assertEquals(1, hostedLocators.get(member).size());
                    final String hostedLocator = hostedLocators.get(member).iterator().next();
                    assertTrue(locators + " does not contain " + hostedLocator, locators.contains(hostedLocator));
                }
            }
        });
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Builder(org.apache.geode.distributed.LocatorLauncher.Builder) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Collection(java.util.Collection) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) File(java.io.File) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Map(java.util.Map) HashSet(java.util.HashSet) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 13 with DistributionManager

use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.

the class DistributedSystemDUnitTest method testWaitForDeparture.

/**
   * ensure that waitForMemberDeparture correctly flushes the serial message queue for the given
   * member
   */
@Test
public void testWaitForDeparture() throws Exception {
    Properties config = new Properties();
    config.put(LOCATORS, "");
    config.put(START_LOCATOR, "localhost[" + this.locatorPort + "]");
    config.put(DISABLE_TCP, "true");
    InternalDistributedSystem system = (InternalDistributedSystem) DistributedSystem.connect(config);
    // construct a member ID that will represent a departed member
    InternalDistributedMember member = new InternalDistributedMember("localhost", 12345, "", "", NORMAL_DM_TYPE, null, null);
    // schedule a message in order to create a queue for the fake member
    DistributionManager distributionManager = (DistributionManager) system.getDistributionManager();
    final FakeMessage message = new FakeMessage(null);
    distributionManager.getExecutor(SERIAL_EXECUTOR, member).execute(new SizeableRunnable(100) {

        @Override
        public void run() {
            // always throws NullPointerException
            message.doAction(distributionManager, false);
        }

        @Override
        public String toString() {
            return "Processing fake message";
        }
    });
    Assert.assertTrue("expected the serial queue to be flushed", distributionManager.getMembershipManager().waitForDeparture(member));
    Assert.assertTrue(message.processed);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) SizeableRunnable(org.apache.geode.distributed.internal.SizeableRunnable) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 14 with DistributionManager

use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.

the class DistributedSystemDUnitTest method testMembershipPortRangeWithExactThreeValues.

@Test
public void testMembershipPortRangeWithExactThreeValues() throws Exception {
    Properties config = new Properties();
    config.setProperty(LOCATORS, "localhost[" + getDUnitLocatorPort() + "]");
    config.setProperty(MEMBERSHIP_PORT_RANGE, this.lowerBoundOfPortRange + "-" + this.upperBoundOfPortRange);
    InternalDistributedSystem system = getSystem(config);
    Cache cache = CacheFactory.create(system);
    cache.addCacheServer();
    DistributionManager dm = (DistributionManager) system.getDistributionManager();
    InternalDistributedMember member = dm.getDistributionManagerId();
    GMSMembershipManager gms = (GMSMembershipManager) MembershipManagerHelper.getMembershipManager(system);
    JGroupsMessenger messenger = (JGroupsMessenger) gms.getServices().getMessenger();
    String jgConfig = messenger.getJGroupsStackConfig();
    assertThat(jgConfig).as("expected to find port_range=\"2\" in " + jgConfig).contains("port_range=\"2\"");
    verifyMembershipPortsInRange(member, this.lowerBoundOfPortRange, this.upperBoundOfPortRange);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) GMSMembershipManager(org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager) JGroupsMessenger(org.apache.geode.distributed.internal.membership.gms.messenger.JGroupsMessenger) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 15 with DistributionManager

use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.

the class DistributedLockServiceDUnitTest method testDestroyLockServiceBeforeGrantRequest.

@Test
public void testDestroyLockServiceBeforeGrantRequest() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    final String serviceName = getUniqueName();
    vm0.invoke(new SerializableRunnable("Create the grantor") {

        public void run() {
            connectDistributedSystem();
            final DistributedLockService service = DistributedLockService.create(serviceName, dlstSystem);
            // lock and unlock to make sure this vm is grantor
            assertTrue(service.lock("obj", -1, -1));
            service.unlock("obj");
        }
    });
    DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

        @Override
        public void beforeSendMessage(DistributionManager dm, DistributionMessage message) {
            if (message instanceof DLockRequestMessage) {
                DistributedLockService.destroy(serviceName);
            }
        }
    });
    connectDistributedSystem();
    final DistributedLockService service = DistributedLockService.create(serviceName, dlstSystem);
    try {
        service.lock("obj", -1, -1);
        fail("The lock service should have been destroyed");
    } catch (LockServiceDestroyedException expected) {
    // Do nothing
    }
    vm0.invoke(new SerializableRunnable("check to make sure the lock is not orphaned") {

        public void run() {
            final DistributedLockService service = DistributedLockService.getServiceNamed(serviceName);
            // lock and unlock to make sure this vm is grantor
            assertTrue(service.lock("obj", -1, -1));
            service.unlock("obj");
        }
    });
}
Also used : DLockRequestMessage(org.apache.geode.distributed.internal.locks.DLockRequestProcessor.DLockRequestMessage) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) DLockTest(org.apache.geode.test.junit.categories.DLockTest)

Aggregations

DistributionManager (org.apache.geode.distributed.internal.DistributionManager)60 Test (org.junit.Test)44 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)36 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)29 DistributionMessageObserver (org.apache.geode.distributed.internal.DistributionMessageObserver)29 VM (org.apache.geode.test.dunit.VM)29 Host (org.apache.geode.test.dunit.Host)28 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)25 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)15 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)12 Cache (org.apache.geode.cache.Cache)11 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)11 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)11 IOException (java.io.IOException)9 IgnoredException (org.apache.geode.test.dunit.IgnoredException)9 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)9 Properties (java.util.Properties)8 UnitTest (org.apache.geode.test.junit.categories.UnitTest)8 RequestImageMessage (org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage)7 Region (org.apache.geode.cache.Region)6