Search in sources :

Example 26 with InternalLocator

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

the class ClusterConfigurationServiceUsingDirDUnitTest method waitForSharedConfiguration.

private void waitForSharedConfiguration(final VM vm) {
    vm.invoke("Waiting for shared configuration", () -> {
        final InternalLocator locator = InternalLocator.getLocator();
        await().until(() -> {
            return locator.isSharedConfigurationRunning();
        });
    });
}
Also used : InternalLocator(org.apache.geode.distributed.internal.InternalLocator)

Example 27 with InternalLocator

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

the class ClusterConfig method verifyLocator.

public void verifyLocator(MemberVM<Locator> locatorVM) {
    Set<String> expectedGroupConfigs = this.getGroups().stream().map(ConfigGroup::getName).collect(toSet());
    // verify info exists in memory
    locatorVM.invoke(() -> {
        InternalLocator internalLocator = LocatorServerStartupRule.locatorStarter.getLocator();
        ClusterConfigurationService sc = internalLocator.getSharedConfiguration();
        // verify no extra configs exist in memory
        Set<String> actualGroupConfigs = sc.getEntireConfiguration().keySet();
        assertThat(actualGroupConfigs).isEqualTo(expectedGroupConfigs);
        for (ConfigGroup configGroup : this.getGroups()) {
            // verify jars are as expected
            Configuration config = sc.getConfiguration(configGroup.name);
            assertThat(config.getJarNames()).isEqualTo(configGroup.getJars());
            // verify property is as expected
            if (StringUtils.isNotBlank(configGroup.getMaxLogFileSize())) {
                Properties props = config.getGemfireProperties();
                assertThat(props.getProperty(LOG_FILE_SIZE_LIMIT)).isEqualTo(configGroup.getMaxLogFileSize());
            }
            // verify region is in the region xml
            for (String regionName : configGroup.getRegions()) {
                String regionXml = "<region name=\"" + regionName + "\"";
                assertThat(config.getCacheXmlContent()).contains(regionXml);
            }
        }
    });
    File clusterConfigDir = new File(locatorVM.getWorkingDir(), "/cluster_config");
    for (ConfigGroup configGroup : this.getGroups()) {
        Set<String> actualFiles = toSetIgnoringHiddenFiles(new File(clusterConfigDir, configGroup.name).list());
        Set<String> expectedFiles = configGroup.getAllFiles();
        assertThat(actualFiles).isEqualTo(expectedFiles);
    }
}
Also used : InternalLocator(org.apache.geode.distributed.internal.InternalLocator) ClusterConfigurationService(org.apache.geode.distributed.internal.ClusterConfigurationService) Configuration(org.apache.geode.management.internal.configuration.domain.Configuration) Properties(java.util.Properties) File(java.io.File)

Example 28 with InternalLocator

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

the class SerialGatewaySenderOperationsDUnitTest method testGatewaySenderNotRegisteredAsCacheServer.

@Test
public void testGatewaySenderNotRegisteredAsCacheServer() {
    Integer lnPort = (Integer) vm0.invoke(() -> WANTestBase.createFirstLocatorWithDSId(1));
    Integer nyPort = (Integer) vm1.invoke(() -> WANTestBase.createFirstRemoteLocator(2, lnPort));
    createCacheInVMs(nyPort, vm2, vm3);
    createReceiverInVMs(vm2, vm3);
    createCacheInVMs(lnPort, vm4, vm5);
    vm4.invoke(() -> WANTestBase.createSender("ln", 2, false, 100, 10, false, true, null, true));
    vm5.invoke(() -> WANTestBase.createSender("ln", 2, false, 100, 10, false, true, null, true));
    startSenderInVMs("ln", vm4, vm5);
    SerializableRunnable check = new SerializableRunnable("assert no cache servers") {

        public void run() {
            InternalLocator inl = (InternalLocator) Locator.getLocator();
            ServerLocator server = inl.getServerLocatorAdvisee();
            LogWriterUtils.getLogWriter().info("Server load map is " + server.getLoadMap());
            assertTrue("expected an empty map but found " + server.getLoadMap(), server.getLoadMap().isEmpty());
            QueueConnectionRequest request = new QueueConnectionRequest(ClientProxyMembershipID.getNewProxyMembership(InternalDistributedSystem.getConnectedInstance()), 1, new HashSet<>(), "", false);
            QueueConnectionResponse response = (QueueConnectionResponse) server.processRequest(request);
            assertTrue("expected no servers but found " + response.getServers(), response.getServers().isEmpty());
        }
    };
    vm0.invoke(check);
    vm1.invoke(check);
}
Also used : QueueConnectionRequest(org.apache.geode.cache.client.internal.locator.QueueConnectionRequest) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) QueueConnectionResponse(org.apache.geode.cache.client.internal.locator.QueueConnectionResponse) ServerLocator(org.apache.geode.distributed.internal.ServerLocator) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 29 with InternalLocator

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

the class ClusterConfigurationServiceEndToEndDUnitTest method setup.

private Object[] setup() throws IOException {
    final int[] ports = getRandomAvailableTCPPorts(3);
    final int locator1Port = ports[0];
    final String locator1Name = "locator1-" + locator1Port;
    final String locatorLogPath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "locator-" + locator1Port + ".log";
    VM locatorAndMgr = getHost(0).getVM(3);
    Object[] result = (Object[]) locatorAndMgr.invoke(new SerializableCallable() {

        @Override
        public Object call() throws IOException {
            int httpPort;
            int jmxPort;
            String jmxHost;
            try {
                jmxHost = InetAddress.getLocalHost().getHostName();
            } catch (UnknownHostException ignore) {
                jmxHost = "localhost";
            }
            final int[] ports = getRandomAvailableTCPPorts(2);
            jmxPort = ports[0];
            httpPort = ports[1];
            final File locatorLogFile = new File(locatorLogPath);
            final Properties locatorProps = new Properties();
            locatorProps.setProperty(NAME, locator1Name);
            locatorProps.setProperty(MCAST_PORT, "0");
            locatorProps.setProperty(LOG_LEVEL, "config");
            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));
            final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator1Port, 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, TIMEOUT, INTERVAL, true);
            final Object[] result = new Object[4];
            result[0] = locator1Port;
            result[1] = jmxHost;
            result[2] = jmxPort;
            result[3] = httpPort;
            return result;
        }
    });
    HeadlessGfsh gfsh = getDefaultShell();
    String jmxHost = (String) result[1];
    int jmxPort = (Integer) result[2];
    int httpPort = (Integer) result[3];
    connect(jmxHost, jmxPort, httpPort, gfsh);
    // Create a cache in VM 1
    VM dataMember = getHost(0).getVM(1);
    dataMember.invoke(new SerializableCallable() {

        @Override
        public Object call() {
            Properties localProps = new Properties();
            localProps.setProperty(MCAST_PORT, "0");
            localProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
            localProps.setProperty(NAME, "DataMember");
            getSystem(localProps);
            InternalCache cache = getCache();
            assertNotNull(cache);
            return getAllNormalMembers(cache);
        }
    });
    return result;
}
Also used : UnknownHostException(java.net.UnknownHostException) HeadlessGfsh(org.apache.geode.management.internal.cli.HeadlessGfsh) InternalCache(org.apache.geode.internal.cache.InternalCache) Properties(java.util.Properties) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) File(java.io.File)

Example 30 with InternalLocator

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

the class DistributedMulticastRegionDUnitTest method startLocator.

private int startLocator() {
    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(3);
    final int locatorPort = ports[0];
    VM locator1Vm = Host.getHost(0).getVM(locatorVM);
    ;
    locator1Vm.invoke(new SerializableCallable() {

        @Override
        public Object call() {
            final File locatorLogFile = new File(getTestMethodName() + "-locator-" + locatorPort + ".log");
            final Properties locatorProps = new Properties();
            locatorProps.setProperty(NAME, "LocatorWithMcast");
            locatorProps.setProperty(MCAST_PORT, mcastport);
            locatorProps.setProperty(MCAST_TTL, mcastttl);
            locatorProps.setProperty(LOG_LEVEL, "info");
            addDSProps(locatorProps);
            // locatorProps.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "true");
            try {
                final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort, null, null, locatorProps);
                System.out.println("test Locator started " + locatorPort);
            } catch (IOException ioex) {
                fail("Unable to create a locator with a shared configuration");
            }
            return null;
        }
    });
    return locatorPort;
}
Also used : InternalLocator(org.apache.geode.distributed.internal.InternalLocator) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) IOException(java.io.IOException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) File(java.io.File)

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