Search in sources :

Example 36 with InternalLocator

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

the class CacheServerLoadMessage method updateLocalLocators.

public void updateLocalLocators() {
    List locators = Locator.getLocators();
    for (int i = 0; i < locators.size(); i++) {
        InternalLocator l = (InternalLocator) locators.get(i);
        ServerLocator serverLocator = l.getServerLocatorAdvisee();
        if (serverLocator != null) {
            serverLocator.updateLoad(location, load, this.clientIds);
        }
    }
}
Also used : InternalLocator(org.apache.geode.distributed.internal.InternalLocator) ArrayList(java.util.ArrayList) List(java.util.List) ServerLocator(org.apache.geode.distributed.internal.ServerLocator)

Example 37 with InternalLocator

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

the class GridAdvisorDUnitTest method test2by2.

/**
   * Tests 2 controllers and 2 bridge servers
   */
@Test
public void test2by2() throws Exception {
    disconnectAllFromDS();
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    VM vm3 = host.getVM(3);
    List<Keeper> freeTCPPorts = AvailablePortHelper.getRandomAvailableTCPPortKeepers(6);
    final Keeper keeper1 = freeTCPPorts.get(0);
    final int port1 = keeper1.getPort();
    final Keeper keeper2 = freeTCPPorts.get(1);
    final int port2 = keeper2.getPort();
    final Keeper bsKeeper1 = freeTCPPorts.get(2);
    final int bsPort1 = bsKeeper1.getPort();
    final Keeper bsKeeper2 = freeTCPPorts.get(3);
    final int bsPort2 = bsKeeper2.getPort();
    final Keeper bsKeeper3 = freeTCPPorts.get(4);
    final int bsPort3 = bsKeeper3.getPort();
    final Keeper bsKeeper4 = freeTCPPorts.get(5);
    final int bsPort4 = bsKeeper4.getPort();
    final String host0 = NetworkUtils.getServerHostName(host);
    final String locators = host0 + "[" + port1 + "]" + "," + host0 + "[" + port2 + "]";
    final Properties dsProps = new Properties();
    dsProps.setProperty(LOCATORS, locators);
    dsProps.setProperty(MCAST_PORT, "0");
    dsProps.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
    dsProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
    keeper1.release();
    vm0.invoke(new SerializableRunnable("Start locator on " + port1) {

        public void run() {
            File logFile = new File(getUniqueName() + "-locator" + port1 + ".log");
            try {
                Locator.startLocatorAndDS(port1, logFile, null, dsProps, true, true, null);
            } catch (IOException ex) {
                Assert.fail("While starting locator on port " + port1, ex);
            }
        }
    });
    // try { Thread.currentThread().sleep(4000); } catch (InterruptedException ie) { }
    keeper2.release();
    vm3.invoke(new SerializableRunnable("Start locators on " + port2) {

        public void run() {
            File logFile = new File(getUniqueName() + "-locator" + port2 + ".log");
            try {
                Locator.startLocatorAndDS(port2, logFile, null, dsProps, true, true, "locator2HNFC");
            } catch (IOException ex) {
                Assert.fail("While starting locator on port " + port2, ex);
            }
        }
    });
    SerializableRunnable connect = new SerializableRunnable("Connect to " + locators) {

        public void run() {
            Properties props = new Properties();
            props.setProperty(MCAST_PORT, "0");
            props.setProperty(LOCATORS, locators);
            dsProps.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
            CacheFactory.create(DistributedSystem.connect(props));
        }
    };
    vm1.invoke(connect);
    vm2.invoke(connect);
    SerializableRunnable startBS1 = new SerializableRunnable("start bridgeServer on " + bsPort1) {

        public void run() {
            try {
                Cache c = CacheFactory.getAnyInstance();
                CacheServer bs = c.addCacheServer();
                bs.setPort(bsPort1);
                bs.setGroups(new String[] { "bs1Group1", "bs1Group2" });
                bs.start();
            } catch (IOException ex) {
                RuntimeException re = new RuntimeException();
                re.initCause(ex);
                throw re;
            }
        }
    };
    SerializableRunnable startBS3 = new SerializableRunnable("start bridgeServer on " + bsPort3) {

        public void run() {
            try {
                Cache c = CacheFactory.getAnyInstance();
                CacheServer bs = c.addCacheServer();
                bs.setPort(bsPort3);
                bs.setGroups(new String[] { "bs3Group1", "bs3Group2" });
                bs.start();
            } catch (IOException ex) {
                RuntimeException re = new RuntimeException();
                re.initCause(ex);
                throw re;
            }
        }
    };
    bsKeeper1.release();
    vm1.invoke(startBS1);
    bsKeeper3.release();
    vm1.invoke(startBS3);
    bsKeeper2.release();
    vm2.invoke(new SerializableRunnable("start bridgeServer on " + bsPort2) {

        public void run() {
            try {
                Cache c = CacheFactory.getAnyInstance();
                CacheServer bs = c.addCacheServer();
                bs.setPort(bsPort2);
                bs.setGroups(new String[] { "bs2Group1", "bs2Group2" });
                bs.start();
            } catch (IOException ex) {
                RuntimeException re = new RuntimeException();
                re.initCause(ex);
                throw re;
            }
        }
    });
    bsKeeper4.release();
    vm2.invoke(new SerializableRunnable("start bridgeServer on " + bsPort4) {

        public void run() {
            try {
                Cache c = CacheFactory.getAnyInstance();
                CacheServer bs = c.addCacheServer();
                bs.setPort(bsPort4);
                bs.setGroups(new String[] { "bs4Group1", "bs4Group2" });
                bs.start();
            } catch (IOException ex) {
                RuntimeException re = new RuntimeException();
                re.initCause(ex);
                throw re;
            }
        }
    });
    // verify that locators know about each other
    vm0.invoke(new SerializableRunnable("Verify other locator on " + port2) {

        public void run() {
            assertTrue(Locator.hasLocator());
            InternalLocator l = (InternalLocator) Locator.getLocator();
            DistributionAdvisee advisee = l.getServerLocatorAdvisee();
            ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
            List others = ca.fetchControllers();
            assertEquals(1, others.size());
            {
                ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(0);
                assertEquals(port2, cp.getPort());
                assertEquals("locator2HNFC", cp.getHost());
            }
            others = ca.fetchBridgeServers();
            assertEquals(4, others.size());
            for (int j = 0; j < others.size(); j++) {
                CacheServerAdvisor.CacheServerProfile bsp = (CacheServerAdvisor.CacheServerProfile) others.get(j);
                if (bsp.getPort() == bsPort1) {
                    assertEquals(Arrays.asList(new String[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort2) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort3) {
                    assertEquals(Arrays.asList(new String[] { "bs3Group1", "bs3Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort4) {
                    assertEquals(Arrays.asList(new String[] { "bs4Group1", "bs4Group2" }), Arrays.asList(bsp.getGroups()));
                } else {
                    fail("unexpected port " + bsp.getPort() + " in " + bsp);
                }
            }
        }
    });
    vm3.invoke(new SerializableRunnable("Verify other locator on " + port1) {

        public void run() {
            assertTrue(Locator.hasLocator());
            InternalLocator l = (InternalLocator) Locator.getLocator();
            DistributionAdvisee advisee = l.getServerLocatorAdvisee();
            ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
            List others = ca.fetchControllers();
            assertEquals(1, others.size());
            {
                ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(0);
                assertEquals(port1, cp.getPort());
            }
            others = ca.fetchBridgeServers();
            assertEquals(4, others.size());
            for (int j = 0; j < others.size(); j++) {
                CacheServerAdvisor.CacheServerProfile bsp = (CacheServerAdvisor.CacheServerProfile) others.get(j);
                if (bsp.getPort() == bsPort1) {
                    assertEquals(Arrays.asList(new String[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort2) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort3) {
                    assertEquals(Arrays.asList(new String[] { "bs3Group1", "bs3Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort4) {
                    assertEquals(Arrays.asList(new String[] { "bs4Group1", "bs4Group2" }), Arrays.asList(bsp.getGroups()));
                } else {
                    fail("unexpected port " + bsp.getPort() + " in " + bsp);
                }
            }
        }
    });
    vm1.invoke(new SerializableRunnable("Verify bridge server view on " + bsPort1 + " and on " + bsPort3) {

        public void run() {
            Cache c = CacheFactory.getAnyInstance();
            List bslist = c.getCacheServers();
            assertEquals(2, bslist.size());
            for (int i = 0; i < bslist.size(); i++) {
                DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
                CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
                List others = bsa.fetchBridgeServers();
                LogWriterUtils.getLogWriter().info("found these bridgeservers in " + advisee + ": " + others);
                assertEquals(3, others.size());
                others = bsa.fetchControllers();
                assertEquals(2, others.size());
                for (int j = 0; j < others.size(); j++) {
                    ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(j);
                    if (cp.getPort() == port1) {
                    // ok
                    } else if (cp.getPort() == port2) {
                        assertEquals("locator2HNFC", cp.getHost());
                    // ok
                    } else {
                        fail("unexpected port " + cp.getPort() + " in " + cp);
                    }
                }
            }
        }
    });
    vm2.invoke(new SerializableRunnable("Verify bridge server view on " + bsPort2 + " and on " + bsPort4) {

        public void run() {
            Cache c = CacheFactory.getAnyInstance();
            List bslist = c.getCacheServers();
            assertEquals(2, bslist.size());
            for (int i = 0; i < bslist.size(); i++) {
                DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
                CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
                List others = bsa.fetchBridgeServers();
                LogWriterUtils.getLogWriter().info("found these bridgeservers in " + advisee + ": " + others);
                assertEquals(3, others.size());
                others = bsa.fetchControllers();
                assertEquals(2, others.size());
                for (int j = 0; j < others.size(); j++) {
                    ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(j);
                    if (cp.getPort() == port1) {
                    // ok
                    } else if (cp.getPort() == port2) {
                        assertEquals("locator2HNFC", cp.getHost());
                    // ok
                    } else {
                        fail("unexpected port " + cp.getPort() + " in " + cp);
                    }
                }
            }
        }
    });
    SerializableRunnable stopBS = new SerializableRunnable("stop bridge server") {

        public void run() {
            Cache c = CacheFactory.getAnyInstance();
            List bslist = c.getCacheServers();
            assertEquals(2, bslist.size());
            CacheServer bs = (CacheServer) bslist.get(0);
            bs.stop();
        }
    };
    vm1.invoke(stopBS);
    // now check to see if everyone else noticed him going away
    vm0.invoke(new SerializableRunnable("Verify other locator on " + port2) {

        public void run() {
            assertTrue(Locator.hasLocator());
            InternalLocator l = (InternalLocator) Locator.getLocator();
            DistributionAdvisee advisee = l.getServerLocatorAdvisee();
            ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
            List others = ca.fetchControllers();
            assertEquals(1, others.size());
            {
                ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(0);
                assertEquals(port2, cp.getPort());
                assertEquals("locator2HNFC", cp.getHost());
            }
            others = ca.fetchBridgeServers();
            assertEquals(3, others.size());
            for (int j = 0; j < others.size(); j++) {
                CacheServerAdvisor.CacheServerProfile bsp = (CacheServerAdvisor.CacheServerProfile) others.get(j);
                if (bsp.getPort() == bsPort2) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort3) {
                    assertEquals(Arrays.asList(new String[] { "bs3Group1", "bs3Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort4) {
                    assertEquals(Arrays.asList(new String[] { "bs4Group1", "bs4Group2" }), Arrays.asList(bsp.getGroups()));
                } else {
                    fail("unexpected port " + bsp.getPort() + " in " + bsp);
                }
            }
        }
    });
    vm3.invoke(new SerializableRunnable("Verify other locator on " + port1) {

        public void run() {
            assertTrue(Locator.hasLocator());
            InternalLocator l = (InternalLocator) Locator.getLocator();
            DistributionAdvisee advisee = l.getServerLocatorAdvisee();
            ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
            List others = ca.fetchControllers();
            assertEquals(1, others.size());
            {
                ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(0);
                assertEquals(port1, cp.getPort());
            }
            others = ca.fetchBridgeServers();
            assertEquals(3, others.size());
            for (int j = 0; j < others.size(); j++) {
                CacheServerAdvisor.CacheServerProfile bsp = (CacheServerAdvisor.CacheServerProfile) others.get(j);
                if (bsp.getPort() == bsPort2) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort3) {
                    assertEquals(Arrays.asList(new String[] { "bs3Group1", "bs3Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort4) {
                    assertEquals(Arrays.asList(new String[] { "bs4Group1", "bs4Group2" }), Arrays.asList(bsp.getGroups()));
                } else {
                    fail("unexpected port " + bsp.getPort() + " in " + bsp);
                }
            }
        }
    });
    SerializableRunnable disconnect = new SerializableRunnable("Disconnect from " + locators) {

        public void run() {
            Properties props = new Properties();
            props.setProperty(MCAST_PORT, "0");
            props.setProperty(LOCATORS, locators);
            DistributedSystem.connect(props).disconnect();
        }
    };
    SerializableRunnable stopLocator = new SerializableRunnable("Stop locator") {

        public void run() {
            assertTrue(Locator.hasLocator());
            Locator.getLocator().stop();
            assertFalse(Locator.hasLocator());
        }
    };
    vm0.invoke(stopLocator);
    // now make sure everyone else saw the locator go away
    vm3.invoke(new SerializableRunnable("Verify locator stopped ") {

        public void run() {
            assertTrue(Locator.hasLocator());
            InternalLocator l = (InternalLocator) Locator.getLocator();
            DistributionAdvisee advisee = l.getServerLocatorAdvisee();
            ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
            List others = ca.fetchControllers();
            assertEquals(0, others.size());
        }
    });
    vm2.invoke(new SerializableRunnable("Verify bridge server saw locator stop") {

        public void run() {
            Cache c = CacheFactory.getAnyInstance();
            List bslist = c.getCacheServers();
            assertEquals(2, bslist.size());
            for (int i = 0; i < bslist.size(); i++) {
                DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
                CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
                List others = bsa.fetchControllers();
                assertEquals(1, others.size());
                for (int j = 0; j < others.size(); j++) {
                    ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(j);
                    if (cp.getPort() == port2) {
                        assertEquals("locator2HNFC", cp.getHost());
                    // ok
                    } else {
                        fail("unexpected port " + cp.getPort() + " in " + cp);
                    }
                }
            }
        }
    });
    vm1.invoke(new SerializableRunnable("Verify bridge server saw locator stop") {

        public void run() {
            Cache c = CacheFactory.getAnyInstance();
            List bslist = c.getCacheServers();
            assertEquals(2, bslist.size());
            for (int i = 0; i < bslist.size(); i++) {
                DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
                if (i == 0) {
                    // skip this one since it is stopped
                    continue;
                }
                CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
                List others = bsa.fetchControllers();
                assertEquals(1, others.size());
                for (int j = 0; j < others.size(); j++) {
                    ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(j);
                    if (cp.getPort() == port2) {
                        assertEquals("locator2HNFC", cp.getHost());
                    // ok
                    } else {
                        fail("unexpected port " + cp.getPort() + " in " + cp);
                    }
                }
            }
        }
    });
    SerializableRunnable restartBS = new SerializableRunnable("restart bridge server") {

        public void run() {
            try {
                Cache c = CacheFactory.getAnyInstance();
                List bslist = c.getCacheServers();
                assertEquals(2, bslist.size());
                CacheServer bs = (CacheServer) bslist.get(0);
                bs.setHostnameForClients("nameForClients");
                bs.start();
            } catch (IOException ex) {
                RuntimeException re = new RuntimeException();
                re.initCause(ex);
                throw re;
            }
        }
    };
    // restart bridge server 1 and see if controller sees it
    vm1.invoke(restartBS);
    vm3.invoke(new SerializableRunnable("Verify bridge server restart ") {

        public void run() {
            assertTrue(Locator.hasLocator());
            InternalLocator l = (InternalLocator) Locator.getLocator();
            DistributionAdvisee advisee = l.getServerLocatorAdvisee();
            ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
            assertEquals(0, ca.fetchControllers().size());
            List others = ca.fetchBridgeServers();
            assertEquals(4, others.size());
            for (int j = 0; j < others.size(); j++) {
                CacheServerAdvisor.CacheServerProfile bsp = (CacheServerAdvisor.CacheServerProfile) others.get(j);
                if (bsp.getPort() == bsPort1) {
                    assertEquals(Arrays.asList(new String[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
                    assertEquals("nameForClients", bsp.getHost());
                } else if (bsp.getPort() == bsPort2) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
                    assertFalse(bsp.getHost().equals("nameForClients"));
                } else if (bsp.getPort() == bsPort3) {
                    assertEquals(Arrays.asList(new String[] { "bs3Group1", "bs3Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort4) {
                    assertEquals(Arrays.asList(new String[] { "bs4Group1", "bs4Group2" }), Arrays.asList(bsp.getGroups()));
                } else {
                    fail("unexpected port " + bsp.getPort() + " in " + bsp);
                }
            }
        }
    });
    vm1.invoke(disconnect);
    vm2.invoke(disconnect);
    // now make sure controller saw all bridge servers stop
    vm3.invoke(new SerializableRunnable("Verify locator stopped ") {

        public void run() {
            assertTrue(Locator.hasLocator());
            InternalLocator l = (InternalLocator) Locator.getLocator();
            DistributionAdvisee advisee = l.getServerLocatorAdvisee();
            ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
            assertEquals(0, ca.fetchControllers().size());
            assertEquals(0, ca.fetchBridgeServers().size());
        }
    });
    vm3.invoke(stopLocator);
}
Also used : DistributionAdvisee(org.apache.geode.distributed.internal.DistributionAdvisee) Keeper(org.apache.geode.internal.AvailablePort.Keeper) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) VM(org.apache.geode.test.dunit.VM) CacheServer(org.apache.geode.cache.server.CacheServer) List(java.util.List) File(java.io.File) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 38 with InternalLocator

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

the class DiskStoreCommandsDUnitTest method testCreateDestroyUpdatesSharedConfig.

/**
   * Asserts that creating and destroying disk stores correctly updates the shared configuration.
   */
// GEODE-1406
@Category(FlakyTest.class)
@Test
public void testCreateDestroyUpdatesSharedConfig() {
    disconnectAllFromDS();
    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
    jmxPort = ports[0];
    httpPort = ports[1];
    try {
        jmxHost = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException ignore) {
        jmxHost = "localhost";
    }
    final String groupName = "testDiskStoreSharedConfigGroup";
    final String diskStoreName = "testDiskStoreSharedConfigDiskStore";
    // Start the Locator and wait for shared configuration to be available
    final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    final Properties locatorProps = new Properties();
    locatorProps.setProperty(NAME, "Locator");
    locatorProps.setProperty(MCAST_PORT, "0");
    locatorProps.setProperty(LOG_LEVEL, "fine");
    locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
    locatorProps.setProperty(JMX_MANAGER, "true");
    locatorProps.setProperty(JMX_MANAGER_START, "true");
    locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
    locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
    locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {

        @Override
        public void run() {
            final File locatorLogFile = new File("locator-" + locatorPort + ".log");
            try {
                final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort, locatorLogFile, null, locatorProps);
                WaitCriterion wc = new WaitCriterion() {

                    @Override
                    public boolean done() {
                        return locator.isSharedConfigurationRunning();
                    }

                    @Override
                    public String description() {
                        return "Waiting for shared configuration to be started";
                    }
                };
                waitForCriterion(wc, 5000, 500, true);
            } catch (IOException ioex) {
                fail("Unable to create a locator with a shared configuration");
            }
        }
    });
    connect(jmxHost, jmxPort, httpPort, getDefaultShell());
    // Create a cache in VM 1
    final File diskStoreDir = new File(new File(".").getAbsolutePath(), diskStoreName);
    this.filesToBeDeleted.add(diskStoreDir.getAbsolutePath());
    VM vm = Host.getHost(0).getVM(1);
    vm.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            diskStoreDir.mkdirs();
            Properties localProps = new Properties();
            localProps.setProperty(MCAST_PORT, "0");
            localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
            localProps.setProperty(GROUPS, groupName);
            getSystem(localProps);
            assertNotNull(getCache());
        }
    });
    // Test creating the disk store
    CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_DISK_STORE);
    commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__NAME, diskStoreName);
    commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__GROUP, groupName);
    commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__DIRECTORY_AND_SIZE, diskStoreDir.getAbsolutePath());
    CommandResult cmdResult = executeCommand(commandStringBuilder.toString());
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    // Make sure the disk store exists in the shared config
    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {

        @Override
        public void run() {
            ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
            String xmlFromConfig;
            try {
                xmlFromConfig = sharedConfig.getConfiguration(groupName).getCacheXmlContent();
                assertTrue(xmlFromConfig.contains(diskStoreName));
            } catch (Exception e) {
                fail("Error occurred in cluster configuration service", e);
            }
        }
    });
    // Restart the cache and make sure it has the diskstore
    vm = Host.getHost(0).getVM(1);
    vm.invoke(new SerializableCallable() {

        @Override
        public Object call() {
            getCache().close();
            Properties localProps = new Properties();
            localProps.setProperty(MCAST_PORT, "0");
            localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
            localProps.setProperty(GROUPS, groupName);
            localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
            getSystem(localProps);
            Cache cache = getCache();
            assertNotNull(cache);
            InternalCache internalCache = (InternalCache) cache;
            Collection<DiskStore> diskStoreList = internalCache.listDiskStores();
            assertNotNull(diskStoreList);
            assertFalse(diskStoreList.isEmpty());
            assertTrue(diskStoreList.size() == 1);
            for (DiskStore diskStore : diskStoreList) {
                assertTrue(diskStore.getName().equals(diskStoreName));
                break;
            }
            return null;
        }
    });
    // Test destroying the disk store
    commandStringBuilder = new CommandStringBuilder(CliStrings.DESTROY_DISK_STORE);
    commandStringBuilder.addOption(CliStrings.DESTROY_DISK_STORE__NAME, diskStoreName);
    commandStringBuilder.addOption(CliStrings.DESTROY_DISK_STORE__GROUP, groupName);
    cmdResult = executeCommand(commandStringBuilder.toString());
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    // Make sure the disk store was removed from the shared config
    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {

        @Override
        public void run() {
            ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
            String xmlFromConfig;
            try {
                xmlFromConfig = sharedConfig.getConfiguration(groupName).getCacheXmlContent();
                assertFalse(xmlFromConfig.contains(diskStoreName));
            } catch (Exception e) {
                fail("Error occurred in cluster configuration service", e);
            }
        }
    });
    // Restart the cache and make sure it DOES NOT have the diskstore
    vm = Host.getHost(0).getVM(1);
    vm.invoke(new SerializableCallable() {

        @Override
        public Object call() {
            getCache().close();
            Properties localProps = new Properties();
            localProps.setProperty(MCAST_PORT, "0");
            localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
            localProps.setProperty(GROUPS, groupName);
            localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
            getSystem(localProps);
            Cache cache = getCache();
            assertNotNull(cache);
            InternalCache internalCache = (InternalCache) cache;
            Collection<DiskStore> diskStores = internalCache.listDiskStores();
            assertNotNull(diskStores);
            assertTrue(diskStores.isEmpty());
            return null;
        }
    });
}
Also used : UnknownHostException(java.net.UnknownHostException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) InternalCache(org.apache.geode.internal.cache.InternalCache) IOException(java.io.IOException) Properties(java.util.Properties) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DiskStore(org.apache.geode.cache.DiskStore) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) ClusterConfigurationService(org.apache.geode.distributed.internal.ClusterConfigurationService) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Collection(java.util.Collection) File(java.io.File) Cache(org.apache.geode.cache.Cache) InternalCache(org.apache.geode.internal.cache.InternalCache) Category(org.junit.experimental.categories.Category) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 39 with InternalLocator

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

the class WANTestBase method checkAllSiteMetaData.

public static void checkAllSiteMetaData(Map<Integer, Set<InetSocketAddress>> dsIdToLocatorAddresses) {
    List<Locator> locatorsConfigured = Locator.getLocators();
    Locator locator = locatorsConfigured.get(0);
    Awaitility.waitAtMost(60, TimeUnit.SECONDS).until(() -> {
        Map<Integer, Set<DistributionLocatorId>> allSiteMetaData = ((InternalLocator) locator).getlocatorMembershipListener().getAllLocatorsInfo();
        for (Map.Entry<Integer, Set<InetSocketAddress>> entry : dsIdToLocatorAddresses.entrySet()) {
            Set<DistributionLocatorId> foundLocatorIds = allSiteMetaData.get(entry.getKey());
            Set<InetSocketAddress> expectedLocators = entry.getValue();
            final Set<InetSocketAddress> foundLocators = foundLocatorIds.stream().map(distributionLocatorId -> new InetSocketAddress(distributionLocatorId.getHostnameForClients(), distributionLocatorId.getPort())).collect(Collectors.toSet());
            assertEquals(expectedLocators, foundLocators);
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EntryEvent(org.apache.geode.cache.EntryEvent) CacheListener(org.apache.geode.cache.CacheListener) Arrays(java.util.Arrays) AttributesFactory(org.apache.geode.cache.AttributesFactory) OrderPolicy(org.apache.geode.cache.wan.GatewaySender.OrderPolicy) LocalRegion(org.apache.geode.internal.cache.LocalRegion) GATEWAY_SSL_KEYSTORE_TYPE(org.apache.geode.distributed.ConfigurationProperties.GATEWAY_SSL_KEYSTORE_TYPE) GatewayEventFilter(org.apache.geode.cache.wan.GatewayEventFilter) GATEWAY_SSL_KEYSTORE(org.apache.geode.distributed.ConfigurationProperties.GATEWAY_SSL_KEYSTORE) InetAddress(java.net.InetAddress) Cache(org.apache.geode.cache.Cache) ConcurrentParallelGatewaySenderQueue(org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue) CacheTestCase(org.apache.geode.cache30.CacheTestCase) Future(java.util.concurrent.Future) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) Map(java.util.Map) ConcurrentSerialGatewaySenderEventProcessor(org.apache.geode.internal.cache.wan.serial.ConcurrentSerialGatewaySenderEventProcessor) REMOTE_LOCATORS(org.apache.geode.distributed.ConfigurationProperties.REMOTE_LOCATORS) CacheServer(org.apache.geode.cache.server.CacheServer) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener) GatewayReceiver(org.apache.geode.cache.wan.GatewayReceiver) Scope(org.apache.geode.cache.Scope) LOCATORS(org.apache.geode.distributed.ConfigurationProperties.LOCATORS) Shipment(org.apache.geode.internal.cache.execute.data.Shipment) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) Set(java.util.Set) Category(org.junit.experimental.categories.Category) Executors(java.util.concurrent.Executors) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Serializable(java.io.Serializable) JUnit4DistributedTestCase(org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase) CacheServerStats(org.apache.geode.internal.cache.tier.sockets.CacheServerStats) Assert.assertFalse(org.junit.Assert.assertFalse) ConcurrentParallelGatewaySenderEventProcessor(org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderEventProcessor) GATEWAY_SSL_ENABLED(org.apache.geode.distributed.ConfigurationProperties.GATEWAY_SSL_ENABLED) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) MCAST_PORT(org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT) Awaitility(org.awaitility.Awaitility) GATEWAY_SSL_CIPHERS(org.apache.geode.distributed.ConfigurationProperties.GATEWAY_SSL_CIPHERS) GATEWAY_SSL_PROTOCOLS(org.apache.geode.distributed.ConfigurationProperties.GATEWAY_SSL_PROTOCOLS) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) CacheFactory(org.apache.geode.cache.CacheFactory) Callable(java.util.concurrent.Callable) AttributesMutator(org.apache.geode.cache.AttributesMutator) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Host(org.apache.geode.test.dunit.Host) VM(org.apache.geode.test.dunit.VM) RegionQueue(org.apache.geode.internal.cache.RegionQueue) ArrayList(java.util.ArrayList) LogWriterUtils(org.apache.geode.test.dunit.LogWriterUtils) Region(org.apache.geode.cache.Region) StringTokenizer(java.util.StringTokenizer) START_LOCATOR(org.apache.geode.distributed.ConfigurationProperties.START_LOCATOR) CacheConfig(org.apache.geode.internal.cache.CacheConfig) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) Properties(java.util.Properties) Assert.assertTrue(org.junit.Assert.assertTrue) GATEWAY_SSL_TRUSTSTORE_PASSWORD(org.apache.geode.distributed.ConfigurationProperties.GATEWAY_SSL_TRUSTSTORE_PASSWORD) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) TestUtil(org.apache.geode.util.test.TestUtil) File(java.io.File) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) ExecutionException(java.util.concurrent.ExecutionException) GatewayQueueEvent(org.apache.geode.cache.wan.GatewayQueueEvent) Assert.assertNull(org.junit.Assert.assertNull) GatewayReceiverFactory(org.apache.geode.cache.wan.GatewayReceiverFactory) GATEWAY_SSL_TRUSTSTORE(org.apache.geode.distributed.ConfigurationProperties.GATEWAY_SSL_TRUSTSTORE) CacheServerTestUtil(org.apache.geode.internal.cache.tier.sockets.CacheServerTestUtil) Assert.assertEquals(org.junit.Assert.assertEquals) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) Customer(org.apache.geode.internal.cache.execute.data.Customer) CONSERVE_SOCKETS(org.apache.geode.distributed.ConfigurationProperties.CONSERVE_SOCKETS) Wait(org.apache.geode.test.dunit.Wait) LOG_LEVEL(org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL) AvailablePort(org.apache.geode.internal.AvailablePort) RegionAttributes(org.apache.geode.cache.RegionAttributes) ParallelGatewaySenderEventProcessor(org.apache.geode.internal.cache.wan.parallel.ParallelGatewaySenderEventProcessor) Assert(org.apache.geode.test.dunit.Assert) CustomerIDPartitionResolver(org.apache.geode.internal.cache.CustomerIDPartitionResolver) AsyncEventQueueImpl(org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl) ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SerialGatewaySenderQueue(org.apache.geode.internal.cache.wan.serial.SerialGatewaySenderQueue) Assert.fail(org.junit.Assert.fail) ThreadFactory(java.util.concurrent.ThreadFactory) JMX_MANAGER(org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER) PoolManager(org.apache.geode.cache.client.PoolManager) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) GATEWAY_SSL_KEYSTORE_PASSWORD(org.apache.geode.distributed.ConfigurationProperties.GATEWAY_SSL_KEYSTORE_PASSWORD) OFF_HEAP_MEMORY_SIZE(org.apache.geode.distributed.ConfigurationProperties.OFF_HEAP_MEMORY_SIZE) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) JMX_MANAGER_HTTP_PORT(org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_HTTP_PORT) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) List(java.util.List) Invoke(org.apache.geode.test.dunit.Invoke) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) SimpleClass(org.apache.geode.pdx.SimpleClass) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) IgnoredException(org.apache.geode.test.dunit.IgnoredException) JMX_MANAGER_PORT(org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT) LocatorDiscoveryCallbackAdapter(org.apache.geode.cache.client.internal.LocatorDiscoveryCallbackAdapter) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) DiskStore(org.apache.geode.cache.DiskStore) DistributionLocatorId(org.apache.geode.internal.admin.remote.DistributionLocatorId) HashMap(java.util.HashMap) DISTRIBUTED_SYSTEM_ID(org.apache.geode.distributed.ConfigurationProperties.DISTRIBUTED_SYSTEM_ID) HashSet(java.util.HashSet) GatewaySenderFactory(org.apache.geode.cache.wan.GatewaySenderFactory) CacheClosedException(org.apache.geode.cache.CacheClosedException) LocatorMembershipListener(org.apache.geode.cache.client.internal.locator.wan.LocatorMembershipListener) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) GatewayTransportFilter(org.apache.geode.cache.wan.GatewayTransportFilter) RegionFactory(org.apache.geode.cache.RegionFactory) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) Pool(org.apache.geode.cache.client.Pool) Locator(org.apache.geode.distributed.Locator) Iterator(java.util.Iterator) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) Assert.assertNotNull(org.junit.Assert.assertNotNull) GATEWAY_SSL_REQUIRE_AUTHENTICATION(org.apache.geode.distributed.ConfigurationProperties.GATEWAY_SSL_REQUIRE_AUTHENTICATION) AvailablePortHelper(org.apache.geode.internal.AvailablePortHelper) AsyncEventQueueFactory(org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory) JMX_MANAGER_START(org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_START) CustId(org.apache.geode.internal.cache.execute.data.CustId) Order(org.apache.geode.internal.cache.execute.data.Order) ParallelGatewaySenderQueue(org.apache.geode.internal.cache.wan.parallel.ParallelGatewaySenderQueue) TimeUnit(java.util.concurrent.TimeUnit) DataPolicy(org.apache.geode.cache.DataPolicy) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) GatewaySender(org.apache.geode.cache.wan.GatewaySender) Collections(java.util.Collections) SimpleClass1(org.apache.geode.pdx.SimpleClass1) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) Locator(org.apache.geode.distributed.Locator) Set(java.util.Set) HashSet(java.util.HashSet) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) DistributionLocatorId(org.apache.geode.internal.admin.remote.DistributionLocatorId) InetSocketAddress(java.net.InetSocketAddress) Map(java.util.Map) HashMap(java.util.HashMap)

Example 40 with InternalLocator

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

the class WANTestBase method checkAllSiteMetaDataFor3Sites.

public static Long checkAllSiteMetaDataFor3Sites(final Map<Integer, Set<String>> dsVsPort) {
    Awaitility.await().atMost(50, TimeUnit.SECONDS).until(() -> assertEquals("System is not initialized", true, (getSystemStatic() != null)));
    List<Locator> locatorsConfigured = Locator.getLocators();
    Locator locator = locatorsConfigured.get(0);
    LocatorMembershipListener listener = ((InternalLocator) locator).getlocatorMembershipListener();
    if (listener == null) {
        fail("No locator membership listener available. WAN is likely not enabled. Is this test in the WAN project?");
    }
    final Map<Integer, Set<DistributionLocatorId>> allSiteMetaData = listener.getAllLocatorsInfo();
    System.out.println("allSiteMetaData : " + allSiteMetaData);
    Awaitility.await().atMost(300, TimeUnit.SECONDS).until(() -> {
        assertEquals(true, (dsVsPort.size() == allSiteMetaData.size()));
        boolean completeFlag = true;
        for (Map.Entry<Integer, Set<String>> entry : dsVsPort.entrySet()) {
            Set<DistributionLocatorId> locators = allSiteMetaData.get(entry.getKey());
            for (String locatorInMetaData : entry.getValue()) {
                DistributionLocatorId locatorId = new DistributionLocatorId(locatorInMetaData);
                if (!locators.contains(locatorId)) {
                    completeFlag = false;
                    break;
                }
            }
            if (false == completeFlag) {
                break;
            }
        }
        assertEquals("Expected site Metadata: " + dsVsPort + " but actual meta data: " + allSiteMetaData, true, completeFlag);
    });
    return System.currentTimeMillis();
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) DistributionLocatorId(org.apache.geode.internal.admin.remote.DistributionLocatorId) LocatorMembershipListener(org.apache.geode.cache.client.internal.locator.wan.LocatorMembershipListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) Locator(org.apache.geode.distributed.Locator) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

InternalLocator (org.apache.geode.distributed.internal.InternalLocator)41 File (java.io.File)21 IOException (java.io.IOException)18 Properties (java.util.Properties)18 Test (org.junit.Test)17 VM (org.apache.geode.test.dunit.VM)16 ClusterConfigurationService (org.apache.geode.distributed.internal.ClusterConfigurationService)15 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)15 Cache (org.apache.geode.cache.Cache)9 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)9 UnknownHostException (java.net.UnknownHostException)8 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)8 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)8 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)7 Locator (org.apache.geode.distributed.Locator)6 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)6 CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)6 List (java.util.List)5 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)5 Set (java.util.Set)4