Search in sources :

Example 6 with RegionShortcut

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

the class RollingUpgrade2DUnitTest method doTestClients.

public void doTestClients(boolean partitioned, String oldVersion) throws Exception {
    final Host host = Host.getHost(0);
    VM locator = host.getVM(oldVersion, 0);
    VM server2 = host.getVM(oldVersion, 1);
    VM server3 = host.getVM(oldVersion, 2);
    VM client = host.getVM(oldVersion, 3);
    final String objectType = "strings";
    final String regionName = "aRegion";
    RegionShortcut shortcut = RegionShortcut.REPLICATE;
    if (partitioned) {
        shortcut = RegionShortcut.PARTITION_REDUNDANT;
    }
    int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(3);
    int[] locatorPorts = new int[] { ports[0] };
    int[] csPorts = new int[] { ports[1], ports[2] };
    DistributedTestUtils.deleteLocatorStateFile(locatorPorts);
    String hostName = NetworkUtils.getServerHostName(host);
    String[] hostNames = new String[] { hostName };
    String locatorString = getLocatorString(locatorPorts);
    try {
        locator.invoke(invokeStartLocator(hostName, locatorPorts[0], getTestMethodName(), getLocatorPropertiesPre91(locatorString)));
        invokeRunnableInVMs(invokeCreateCache(getSystemProperties(locatorPorts)), server2, server3);
        invokeRunnableInVMs(invokeStartCacheServer(csPorts[0]), server2);
        invokeRunnableInVMs(invokeStartCacheServer(csPorts[1]), server3);
        invokeRunnableInVMs(invokeCreateClientCache(getClientSystemProperties(), hostNames, locatorPorts), client);
        // invokeRunnableInVMs(invokeAssertVersion(oldOrdinal), server2, server3, client);
        invokeRunnableInVMs(invokeCreateRegion(regionName, shortcut), server2, server3);
        invokeRunnableInVMs(invokeCreateClientRegion(regionName, ClientRegionShortcut.PROXY), client);
        putAndVerify(objectType, client, regionName, 0, 10, server3, client);
        putAndVerify(objectType, server3, regionName, 100, 110, server3, client);
        locator = rollLocatorToCurrent(locator, hostName, locatorPorts[0], getTestMethodName(), locatorString);
        server3 = rollServerToCurrentAndCreateRegion(server3, shortcut, regionName, locatorPorts);
        invokeRunnableInVMs(invokeStartCacheServer(csPorts[1]), server3);
        putAndVerify(objectType, client, regionName, 15, 25, server3, client);
        putAndVerify(objectType, server3, regionName, 20, 30, server3, client);
        server2 = rollServerToCurrentAndCreateRegion(server2, shortcut, regionName, locatorPorts);
        invokeRunnableInVMs(invokeStartCacheServer(csPorts[0]), server2);
        putAndVerify(objectType, client, regionName, 25, 35, server2, client);
        putAndVerify(objectType, server2, regionName, 30, 40, server3, client);
        client = rollClientToCurrentAndCreateRegion(client, ClientRegionShortcut.PROXY, regionName, hostNames, locatorPorts);
        putAndVerify(objectType, client, regionName, 35, 45, server2, server3);
        putAndVerify(objectType, server2, regionName, 40, 50, server3, client);
    } finally {
        invokeRunnableInVMs(true, invokeStopLocator(), locator);
        invokeRunnableInVMs(true, invokeCloseCache(), server2, server3, client);
    }
}
Also used : VM(org.apache.geode.test.dunit.VM) ClientRegionShortcut(org.apache.geode.cache.client.ClientRegionShortcut) RegionShortcut(org.apache.geode.cache.RegionShortcut) Host(org.apache.geode.test.dunit.Host)

Example 7 with RegionShortcut

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

the class RollingUpgrade2DUnitTest method doTestRollTwoLocatorsWithTwoServers.

// 2 locator, 2 servers
public void doTestRollTwoLocatorsWithTwoServers(boolean partitioned, String oldVersion) throws Exception {
    final Host host = Host.getHost(0);
    VM server1 = host.getVM(oldVersion, 0);
    VM server2 = host.getVM(oldVersion, 1);
    VM server3 = host.getVM(oldVersion, 2);
    VM server4 = host.getVM(oldVersion, 3);
    final String objectType = "strings";
    final String regionName = "aRegion";
    RegionShortcut shortcut = RegionShortcut.REPLICATE;
    if (partitioned) {
        shortcut = RegionShortcut.PARTITION_REDUNDANT;
    }
    int[] locatorPorts = AvailablePortHelper.getRandomAvailableTCPPorts(2);
    DistributedTestUtils.deleteLocatorStateFile(locatorPorts);
    String hostName = NetworkUtils.getServerHostName(host);
    String locatorString = getLocatorString(locatorPorts);
    try {
        server1.invoke(invokeStartLocator(hostName, locatorPorts[0], getTestMethodName(), getLocatorPropertiesPre91(locatorString)));
        server2.invoke(invokeStartLocator(hostName, locatorPorts[1], getTestMethodName(), getLocatorPropertiesPre91(locatorString)));
        invokeRunnableInVMs(invokeCreateCache(getSystemProperties(locatorPorts)), server3, server4);
        // invokeRunnableInVMs(invokeAssertVersion(oldOrdinal), server3, server4);
        invokeRunnableInVMs(invokeCreateRegion(regionName, shortcut), server3, server4);
        putAndVerify(objectType, server3, regionName, 0, 10, server3, server4);
        server1 = rollLocatorToCurrent(server1, hostName, locatorPorts[0], getTestMethodName(), locatorString);
        server2 = rollLocatorToCurrent(server2, hostName, locatorPorts[1], getTestMethodName(), locatorString);
        server3 = rollServerToCurrentAndCreateRegion(server3, shortcut, regionName, locatorPorts);
        putAndVerify(objectType, server4, regionName, 15, 25, server3, server4);
        putAndVerify(objectType, server3, regionName, 20, 30, server3, server4);
        server4 = rollServerToCurrentAndCreateRegion(server4, shortcut, regionName, locatorPorts);
        putAndVerify(objectType, server4, regionName, 25, 35, server3, server4);
        putAndVerify(objectType, server3, regionName, 30, 40, server3, server4);
    } finally {
        invokeRunnableInVMs(true, invokeStopLocator(), server1, server2);
        invokeRunnableInVMs(true, invokeCloseCache(), server3, server4);
    }
}
Also used : VM(org.apache.geode.test.dunit.VM) ClientRegionShortcut(org.apache.geode.cache.client.ClientRegionShortcut) RegionShortcut(org.apache.geode.cache.RegionShortcut) Host(org.apache.geode.test.dunit.Host)

Example 8 with RegionShortcut

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

the class RollingUpgrade2DUnitTest method testOplogMagicSeqBackwardCompactibility.

// TODO file a JIRA ticket
// java.lang.AssertionError
// at org.junit.Assert.fail(Assert.java:86)
// at org.junit.Assert.assertTrue(Assert.java:41)
// at org.junit.Assert.assertFalse(Assert.java:64)
// at org.junit.Assert.assertFalse(Assert.java:74)
// at
// org.apache.geode.internal.cache.rollingupgrade.RollingUpgrade2DUnitTest.verifyOplogHeader(RollingUpgrade2DUnitTest.java:633)
// at
// org.apache.geode.internal.cache.rollingupgrade.RollingUpgrade2DUnitTest.testOplogMagicSeqBackwardCompactibility(RollingUpgrade2DUnitTest.java:568)
@Ignore("GEODE-2355: test fails consistently")
@Test
public void testOplogMagicSeqBackwardCompactibility() throws Exception {
    String objectType = "strings";
    String regionType = "persistentReplicate";
    final Host host = Host.getHost(0);
    VM server1 = host.getVM(oldVersion, 0);
    VM server2 = host.getVM(oldVersion, 1);
    VM server3 = host.getVM(oldVersion, 2);
    VM locator = host.getVM(oldVersion, 3);
    String regionName = "aRegion";
    RegionShortcut shortcut = RegionShortcut.REPLICATE_PERSISTENT;
    for (int i = 0; i < testingDirs.length; i++) {
        testingDirs[i] = new File(diskDir, "diskStoreVM_" + String.valueOf(host.getVM(i).getPid())).getAbsoluteFile();
        if (!testingDirs[i].exists()) {
            System.out.println(" Creating diskdir for server: " + i);
            testingDirs[i].mkdirs();
        }
    }
    int[] locatorPorts = AvailablePortHelper.getRandomAvailableTCPPorts(1);
    String hostName = NetworkUtils.getServerHostName(host);
    String locatorsString = getLocatorString(locatorPorts);
    DistributedTestUtils.deleteLocatorStateFile(locatorPorts);
    try {
        locator.invoke(invokeStartLocator(hostName, locatorPorts[0], getTestMethodName(), getLocatorPropertiesPre91(locatorsString)));
        invokeRunnableInVMs(invokeCreateCache(getSystemProperties(locatorPorts)), server1, server2, server3);
        // create region
        for (int i = 0; i < testingDirs.length; i++) {
            CacheSerializableRunnable runnable = invokeCreatePersistentReplicateRegion(regionName, testingDirs[i]);
            invokeRunnableInVMs(runnable, host.getVM(i));
        }
        putAndVerify("strings", server1, regionName, 0, 10, server2, server3);
        // before upgrade headers will be absent
        HashSet<String> oldFormatFiles = verifyOplogHeader(testingDirs[0], null);
        locator = rollLocatorToCurrent(locator, hostName, locatorPorts[0], getTestMethodName(), locatorsString);
        server1 = rollServerToCurrentAndCreateRegion(server1, regionType, testingDirs[0], shortcut, regionName, locatorPorts);
        System.out.println(verifyOplogHeader(testingDirs[0], oldFormatFiles));
        verifyValues(objectType, regionName, 0, 10, server1);
        putAndVerify(objectType, server1, regionName, 5, 15, server2, server3);
        putAndVerify(objectType, server2, regionName, 10, 20, server1, server3);
        System.out.println(verifyOplogHeader(testingDirs[0], oldFormatFiles));
        System.out.println(verifyOplogHeader(testingDirs[1], null));
    } finally {
        invokeRunnableInVMs(true, invokeStopLocator(), locator);
        invokeRunnableInVMs(true, invokeCloseCache(), server1, server2, server3);
        if ((regionType.equals("persistentReplicate"))) {
            deleteDiskStores();
        }
    }
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) ClientRegionShortcut(org.apache.geode.cache.client.ClientRegionShortcut) RegionShortcut(org.apache.geode.cache.RegionShortcut) Host(org.apache.geode.test.dunit.Host) DiskInitFile(org.apache.geode.internal.cache.DiskInitFile) File(java.io.File) Ignore(org.junit.Ignore) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) BackwardCompatibilityTest(org.apache.geode.test.junit.categories.BackwardCompatibilityTest) Test(org.junit.Test)

Example 9 with RegionShortcut

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

the class RollingUpgrade2DUnitTest method doTestQueryMixedServers.

public void doTestQueryMixedServers(boolean partitioned, String oldVersion) throws Exception {
    final Host host = Host.getHost(0);
    VM currentServer1 = host.getVM(0);
    VM oldServer = host.getVM(oldVersion, 1);
    VM currentServer2 = host.getVM(2);
    VM oldServerAndLocator = host.getVM(oldVersion, 3);
    String regionName = "cqs";
    RegionShortcut shortcut = RegionShortcut.REPLICATE;
    if (partitioned) {
        shortcut = RegionShortcut.PARTITION;
    }
    String serverHostName = NetworkUtils.getServerHostName(Host.getHost(0));
    int port = AvailablePortHelper.getRandomAvailableTCPPort();
    try {
        Properties props = getSystemProperties();
        props.remove(DistributionConfig.LOCATORS_NAME);
        invokeRunnableInVMs(invokeStartLocatorAndServer(serverHostName, port, props), oldServerAndLocator);
        props.put(DistributionConfig.LOCATORS_NAME, serverHostName + "[" + port + "]");
        invokeRunnableInVMs(invokeCreateCache(props), currentServer1, currentServer2, oldServer);
        currentServer1.invoke(invokeAssertVersion(Version.CURRENT_ORDINAL));
        currentServer2.invoke(invokeAssertVersion(Version.CURRENT_ORDINAL));
        // oldServer.invoke(invokeAssertVersion(oldOrdinal));
        // oldServerAndLocator.invoke(invokeAssertVersion(oldOrdinal));
        // create region
        invokeRunnableInVMs(invokeCreateRegion(regionName, shortcut), currentServer1, currentServer2, oldServer, oldServerAndLocator);
        putDataSerializableAndVerify(currentServer1, regionName, 0, 100, currentServer2, oldServer, oldServerAndLocator);
        query("Select * from /" + regionName + " p where p.timeout > 0L", 99, currentServer1, currentServer2, oldServer, oldServerAndLocator);
    } finally {
        invokeRunnableInVMs(invokeCloseCache(), currentServer1, currentServer2, oldServer, oldServerAndLocator);
    }
}
Also used : VM(org.apache.geode.test.dunit.VM) ClientRegionShortcut(org.apache.geode.cache.client.ClientRegionShortcut) RegionShortcut(org.apache.geode.cache.RegionShortcut) Host(org.apache.geode.test.dunit.Host) Properties(java.util.Properties)

Example 10 with RegionShortcut

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

the class OutOfOffHeapMemoryDUnitTest method testOtherMembersSeeOutOfOffHeapMemoryMemberDisconnects.

@Test
public void testOtherMembersSeeOutOfOffHeapMemoryMemberDisconnects() {
    final int vmCount = Host.getHost(0).getVMCount();
    final String name = getRegionName();
    final RegionShortcut shortcut = getRegionShortcut();
    final int biggerVM = 0;
    final int smallerVM = 1;
    Host.getHost(0).getVM(smallerVM).invoke(new SerializableRunnable() {

        public void run() {
            OutOfOffHeapMemoryDUnitTest.isSmallerVM.set(true);
        }
    });
    // create off-heap region in all members
    for (int i = 0; i < vmCount; i++) {
        Host.getHost(0).getVM(i).invoke(new SerializableRunnable() {

            public void run() {
                OutOfOffHeapMemoryDUnitTest.cache.set(getCache());
                OutOfOffHeapMemoryDUnitTest.system.set(getSystem());
                final Region<Object, Object> region = OutOfOffHeapMemoryDUnitTest.cache.get().createRegionFactory(shortcut).setOffHeap(true).create(name);
                assertNotNull(region);
            }
        });
    }
    // make sure there are vmCount+1 members total
    for (int i = 0; i < vmCount; i++) {
        Host.getHost(0).getVM(i).invoke(new SerializableRunnable() {

            public void run() {
                assertFalse(OutOfOffHeapMemoryDUnitTest.cache.get().isClosed());
                assertTrue(OutOfOffHeapMemoryDUnitTest.system.get().isConnected());
                // +1 for locator
                final int countMembersPlusLocator = vmCount + 1;
                // -1 one for self
                final int countOtherMembers = vmCount - 1;
                assertEquals(countMembersPlusLocator, ((InternalDistributedSystem) OutOfOffHeapMemoryDUnitTest.system.get()).getDistributionManager().getDistributionManagerIds().size());
                assertEquals(countOtherMembers, ((DistributedRegion) OutOfOffHeapMemoryDUnitTest.cache.get().getRegion(name)).getDistributionAdvisor().getNumProfiles());
            }
        });
    }
    // perform puts in bigger member until smaller member goes OOOHME
    Host.getHost(0).getVM(biggerVM).invoke(new SerializableRunnable() {

        public void run() {
            final long TIME_LIMIT = 30 * 1000;
            final StopWatch stopWatch = new StopWatch(true);
            // -1 for self
            int countOtherMembers = vmCount - 1;
            // -1 for self, -1 for smallerVM
            final int countOtherMembersMinusSmaller = vmCount - 1 - 1;
            final Region<Object, Object> region = OutOfOffHeapMemoryDUnitTest.cache.get().getRegion(name);
            for (int i = 0; countOtherMembers > countOtherMembersMinusSmaller; i++) {
                region.put("key-" + i, new byte[1024]);
                countOtherMembers = ((DistributedRegion) OutOfOffHeapMemoryDUnitTest.cache.get().getRegion(name)).getDistributionAdvisor().getNumProfiles();
                assertTrue("puts failed to push member out of off-heap memory within time limit", stopWatch.elapsedTimeMillis() < TIME_LIMIT);
            }
            assertEquals("Member did not depart from OutOfOffHeapMemory", countOtherMembersMinusSmaller, countOtherMembers);
        }
    });
    // verify that member with OOOHME closed
    Host.getHost(0).getVM(smallerVM).invoke(new SerializableRunnable() {

        public void run() {
            assertTrue(OutOfOffHeapMemoryDUnitTest.cache.get().isClosed());
            assertFalse(OutOfOffHeapMemoryDUnitTest.system.get().isConnected());
        }
    });
    // verify that all other members noticed smaller member closed
    for (int i = 0; i < vmCount; i++) {
        if (i == smallerVM) {
            continue;
        }
        Host.getHost(0).getVM(i).invoke(new SerializableRunnable() {

            public void run() {
                // +1 for locator, -1 for OOOHME
                final int countMembersPlusLocator = vmCount + 1 - 1;
                // member
                // -1 for self, -1 for OOOHME member
                final int countOtherMembers = vmCount - 1 - 1;
                with().pollInterval(10, TimeUnit.MILLISECONDS).await().atMost(30, TimeUnit.SECONDS).until(numDistributionManagers(), equalTo(countMembersPlusLocator));
                with().pollInterval(10, TimeUnit.MILLISECONDS).await().atMost(30, TimeUnit.SECONDS).until(numProfiles(), equalTo(countOtherMembers));
            }

            private Callable<Integer> numProfiles() {
                return () -> {
                    DistributedRegion dr = (DistributedRegion) OutOfOffHeapMemoryDUnitTest.cache.get().getRegion(name);
                    return dr.getDistributionAdvisor().getNumProfiles();
                };
            }

            private Callable<Integer> numDistributionManagers() {
                return () -> {
                    InternalDistributedSystem ids = (InternalDistributedSystem) OutOfOffHeapMemoryDUnitTest.system.get();
                    return ids.getDistributionManager().getDistributionManagerIds().size();
                };
            }
        });
    }
}
Also used : RegionShortcut(org.apache.geode.cache.RegionShortcut) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Callable(java.util.concurrent.Callable) StopWatch(org.apache.geode.internal.util.StopWatch) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

RegionShortcut (org.apache.geode.cache.RegionShortcut)16 ClientRegionShortcut (org.apache.geode.cache.client.ClientRegionShortcut)11 Host (org.apache.geode.test.dunit.Host)9 VM (org.apache.geode.test.dunit.VM)9 Properties (java.util.Properties)5 Test (org.junit.Test)3 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)2 Compressor (org.apache.geode.compression.Compressor)2 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 CacheFactory (org.apache.geode.cache.CacheFactory)1 CacheListener (org.apache.geode.cache.CacheListener)1 CacheLoader (org.apache.geode.cache.CacheLoader)1 CacheWriter (org.apache.geode.cache.CacheWriter)1 DataPolicy (org.apache.geode.cache.DataPolicy)1