Search in sources :

Example 6 with InternalLocator

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

the class GridAdvisorDUnitTest method test2by2usingGroups.

@Test
public void test2by2usingGroups() 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 locators 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);
            }
        }
    });
    vm1.invoke(new SerializableRunnable("Connect to " + locators) {

        public void run() {
            Properties props = new Properties();
            props.setProperty(MCAST_PORT, "0");
            props.setProperty(LOCATORS, locators);
            props.setProperty(GROUPS, "bs1Group1, bs1Group2");
            props.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
            CacheFactory.create(DistributedSystem.connect(props));
        }
    });
    vm2.invoke(new SerializableRunnable("Connect to " + locators) {

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

        public void run() {
            try {
                Cache c = CacheFactory.getAnyInstance();
                CacheServer bs = c.addCacheServer();
                bs.setPort(bsPort1);
                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.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.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.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[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort4) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), 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[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort4) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), 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[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort4) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), 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[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort4) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
                } else {
                    fail("unexpected port " + bsp.getPort() + " in " + bsp);
                }
            }
        }
    });
    SerializableRunnable disconnect = new SerializableRunnable("Disconnect from " + locators) {

        public void run() {
            InternalDistributedSystem.getAnyInstance().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[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort4) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), 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 7 with InternalLocator

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

the class QueueCommandsDUnitTest method testCreateUpdatesSharedConfig.

/**
   * Asserts that creating async event queues correctly updates the shared configuration.
   */
// GEODE-1976
@Category(FlakyTest.class)
@Test
public void testCreateUpdatesSharedConfig() throws IOException {
    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 queueName = "testAsyncEventQueueQueue";
    final String groupName = "testAsyncEventQueueSharedConfigGroup";
    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));
    // Start the Locator and wait for shared configuration to be available
    final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    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
    VM vm = Host.getHost(0).getVM(1);
    vm.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            Properties localProps = new Properties();
            localProps.setProperty(MCAST_PORT, "0");
            localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
            localProps.setProperty(GROUPS, groupName);
            getSystem(localProps);
            assertNotNull(getCache());
        }
    });
    // Deploy a JAR file with an AsyncEventListener that can be instantiated on each server
    final File jarFile = new File(new File(".").getAbsolutePath(), "QueueCommandsDUnit.jar");
    QueueCommandsDUnitTest.this.filesToBeDeleted.add(jarFile.getAbsolutePath());
    ClassBuilder classBuilder = new ClassBuilder();
    byte[] jarBytes = classBuilder.createJarFromClassContent("com/qcdunit/QueueCommandsDUnitTestListener", "package com.qcdunit;" + "import java.util.List; import java.util.Properties;" + "import org.apache.geode.internal.cache.xmlcache.Declarable2; import org.apache.geode.cache.asyncqueue.AsyncEvent;" + "import org.apache.geode.cache.asyncqueue.AsyncEventListener;" + "public class QueueCommandsDUnitTestListener implements Declarable2, AsyncEventListener {" + "Properties props;" + "public boolean processEvents(List<AsyncEvent> events) { return true; }" + "public void close() {}" + "public void init(final Properties props) {this.props = props;}" + "public Properties getConfig() {return this.props;}}");
    writeJarBytesToFile(jarFile, jarBytes);
    CommandResult cmdResult = executeCommand("deploy --jar=QueueCommandsDUnit.jar");
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    // Test creating the queue
    CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_ASYNC_EVENT_QUEUE);
    commandStringBuilder.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__ID, queueName);
    commandStringBuilder.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__GROUP, groupName);
    commandStringBuilder.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__LISTENER, "com.qcdunit.QueueCommandsDUnitTestListener");
    cmdResult = executeCommand(commandStringBuilder.toString());
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    // Make sure the queue 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(queueName));
            } catch (Exception e) {
                fail("Error occurred in cluster configuration service", e);
            }
        }
    });
    // Close cache in the vm1 and restart it to get the shared configuration
    vm = Host.getHost(0).getVM(1);
    vm.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            Cache cache = getCache();
            assertNotNull(cache);
            cache.close();
            assertTrue(cache.isClosed());
            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 = getCache();
            assertNotNull(cache);
            AsyncEventQueue aeq = cache.getAsyncEventQueue(queueName);
            assertNotNull(aeq);
        }
    });
}
Also used : UnknownHostException(java.net.UnknownHostException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) IOException(java.io.IOException) Properties(java.util.Properties) ClassBuilder(org.apache.geode.internal.ClassBuilder) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) 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) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) File(java.io.File) Cache(org.apache.geode.cache.Cache) 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 8 with InternalLocator

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

the class LocatorLauncherLocalIntegrationTest method testBuilderSetProperties.

@Test
public void testBuilderSetProperties() throws Throwable {
    this.launcher = new Builder().setForce(true).setMemberName(getUniqueName()).setPort(this.locatorPort).setWorkingDirectory(this.workingDirectory).set(CLUSTER_CONFIGURATION_DIR, this.clusterConfigDirectory).set(DISABLE_AUTO_RECONNECT, "true").set(LOG_LEVEL, "config").set(MCAST_PORT, "0").build();
    try {
        assertEquals(Status.ONLINE, this.launcher.start().getStatus());
        waitForLocatorToStart(this.launcher, true);
        final InternalLocator locator = this.launcher.getLocator();
        assertNotNull(locator);
        final DistributedSystem distributedSystem = locator.getDistributedSystem();
        assertNotNull(distributedSystem);
        assertEquals("true", distributedSystem.getProperties().getProperty(DISABLE_AUTO_RECONNECT));
        assertEquals("0", distributedSystem.getProperties().getProperty(MCAST_PORT));
        assertEquals("config", distributedSystem.getProperties().getProperty(LOG_LEVEL));
        assertEquals(getUniqueName(), distributedSystem.getProperties().getProperty(NAME));
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    try {
        assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
        assertNull(this.launcher.getLocator());
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
}
Also used : InternalLocator(org.apache.geode.distributed.internal.InternalLocator) Builder(org.apache.geode.distributed.LocatorLauncher.Builder) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 9 with InternalLocator

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

the class LocatorJUnitTest method testHandlersAreWaitedOn.

/**
   * GEODE-2253 - a locator should handle a SharedConfigurationStatusRequest regardless of whether
   * it has the service or not
   */
@Test
public void testHandlersAreWaitedOn() throws Exception {
    Properties dsprops = new Properties();
    int jmxPort = getRandomAvailablePort(SOCKET);
    dsprops.setProperty(MCAST_PORT, "0");
    dsprops.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
    // seconds
    dsprops.setProperty(LOCATOR_WAIT_TIME, "1");
    dsprops.setProperty(LOG_FILE, "");
    locator = Locator.startLocatorAndDS(port, null, dsprops);
    InternalLocator internalLocator = (InternalLocator) locator;
    // the locator should always install a SharedConfigurationStatusRequest handler
    assertTrue(internalLocator.hasHandlerForClass(SharedConfigurationStatusRequest.class));
    // the locator should wait if a handler isn't installed
    assertFalse(internalLocator.hasHandlerForClass(ConfigurationRequest.class));
    ConfigurationRequest request = new ConfigurationRequest();
    Object result = internalLocator.getPrimaryHandler().processRequest(request);
    assertNull(result);
    assertTrue(internalLocator.getPrimaryHandler().hasWaitedForHandlerInitialization());
}
Also used : InternalLocator(org.apache.geode.distributed.internal.InternalLocator) ConfigurationRequest(org.apache.geode.management.internal.configuration.messages.ConfigurationRequest) SharedConfigurationStatusRequest(org.apache.geode.management.internal.configuration.messages.SharedConfigurationStatusRequest) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 10 with InternalLocator

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

the class MyDistributedSystemListener method addedDistributedSystem.

/**
   * Please note that dynamic addition of the sender id to region is not yet available.
   */
public void addedDistributedSystem(int remoteDsId) {
    addCount++;
    List<Locator> locatorsConfigured = Locator.getLocators();
    Locator locator = locatorsConfigured.get(0);
    Map<Integer, Set<DistributionLocatorId>> allSiteMetaData = ((InternalLocator) locator).getlocatorMembershipListener().getAllLocatorsInfo();
    System.out.println("Added : allSiteMetaData : " + allSiteMetaData);
}
Also used : Locator(org.apache.geode.distributed.Locator) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) Set(java.util.Set)

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