Search in sources :

Example 1 with Server

use of org.apache.geode.test.dunit.rules.Server in project geode by apache.

the class PDXGfshPostProcessorOnRemoteServerTest method testGfshCommand.

@Test
public void testGfshCommand() throws Exception {
    Properties locatorProps = new Properties();
    locatorProps.setProperty(TestSecurityManager.SECURITY_JSON, "org/apache/geode/management/internal/security/clientServer.json");
    locatorProps.setProperty(SECURITY_MANAGER, TestSecurityManager.class.getName());
    locatorProps.setProperty(SECURITY_POST_PROCESSOR, PDXPostProcessor.class.getName());
    MemberVM<Locator> locatorVM = lsRule.startLocatorVM(0, locatorProps);
    Properties serverProps = new Properties();
    serverProps.setProperty(TestSecurityManager.SECURITY_JSON, "org/apache/geode/management/internal/security/clientServer.json");
    serverProps.setProperty("security-username", "super-user");
    serverProps.setProperty("security-password", "1234567");
    MemberVM<Server> serverVM = lsRule.startServerVM(1, serverProps, locatorVM.getPort());
    serverVM.invoke(() -> {
        Cache cache = LocatorServerStartupRule.serverStarter.getCache();
        Region region = cache.createRegionFactory(RegionShortcut.REPLICATE).create(REGION_NAME);
        for (int i = 0; i < 5; i++) {
            SimpleClass obj = new SimpleClass(i, (byte) i);
            region.put("key" + i, obj);
        }
    });
    // wait until the region bean is visible
    locatorVM.invoke(() -> {
        Awaitility.await().pollInterval(500, TimeUnit.MICROSECONDS).atMost(5, TimeUnit.SECONDS).until(() -> {
            Cache cache = CacheFactory.getAnyInstance();
            Object bean = ManagementService.getManagementService(cache).getDistributedRegionMXBean("/" + REGION_NAME);
            return bean != null;
        });
    });
    gfsh.connectAndVerify(locatorVM.getJmxPort(), GfshShellConnectionRule.PortType.jmxManger, CliStrings.CONNECT__USERNAME, "dataUser", CliStrings.CONNECT__PASSWORD, "1234567");
    // get command
    CommandResult result = gfsh.executeAndVerifyCommand("get --key=key1 --region=AuthRegion");
    assertTrue(result.getContent().toString().contains(SimpleClass.class.getName()));
    gfsh.executeAndVerifyCommand("query --query=\"select * from /AuthRegion\"");
    serverVM.invoke(() -> {
        PDXPostProcessor pp = (PDXPostProcessor) SecurityService.getSecurityService().getPostProcessor();
        // verify that the post processor is called 6 times. (5 for the query, 1 for the get)
        assertEquals(pp.getCount(), 6);
    });
}
Also used : Server(org.apache.geode.test.dunit.rules.Server) Properties(java.util.Properties) SimpleClass(org.apache.geode.pdx.SimpleClass) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Locator(org.apache.geode.test.dunit.rules.Locator) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 2 with Server

use of org.apache.geode.test.dunit.rules.Server in project geode by apache.

the class ExportLogsOnServerManagerDUnit method testExportWithPeerLocator.

@Test
public void testExportWithPeerLocator() throws Exception {
    MemberVM<Server> server0 = lsRule.startServerAsEmbededLocator(0);
    lsRule.startServerVM(1, server0.getMember().getEmbeddedLocatorPort());
    gfshConnector.connect(server0.getMember().getEmbeddedLocatorPort(), GfshShellConnectionRule.PortType.locator);
    gfshConnector.executeAndVerifyCommand("export logs");
    String message = gfshConnector.getGfshOutput();
    assertThat(message).contains(server0.getWorkingDir().getAbsolutePath());
    String zipPath = getZipPathFromCommandResult(message);
    Set<String> expectedZipEntries = Sets.newHashSet("server-0/server-0.log", "server-1/server-1.log");
    Set<String> actualZipEnries = new ZipFile(zipPath).stream().map(ZipEntry::getName).collect(Collectors.toSet());
    assertThat(actualZipEnries).isEqualTo(expectedZipEntries);
}
Also used : Server(org.apache.geode.test.dunit.rules.Server) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 3 with Server

use of org.apache.geode.test.dunit.rules.Server in project geode by apache.

the class ClusterConfig method verifyServer.

public void verifyServer(MemberVM<Server> serverVM) {
    // verify files exist in filesystem
    Set<String> expectedJarNames = this.getJarNames().stream().collect(toSet());
    String[] actualJarFiles = serverVM.getWorkingDir().list((dir, filename) -> filename.contains(".jar"));
    Set<String> actualJarNames = Stream.of(actualJarFiles).map(jar -> jar.replaceAll("\\.v\\d+\\.jar", ".jar")).collect(toSet());
    // We will end up with extra jars on disk if they are deployed and then undeployed
    assertThat(expectedJarNames).isSubsetOf(actualJarNames);
    // verify config exists in memory
    serverVM.invoke(() -> {
        Cache cache = GemFireCacheImpl.getInstance();
        // TODO: set compare to fail if there are extra regions
        for (String region : this.getRegions()) {
            assertThat(cache.getRegion(region)).isNotNull();
        }
        if (StringUtils.isNotBlank(this.getMaxLogFileSize())) {
            Properties props = cache.getDistributedSystem().getProperties();
            assertThat(props.getProperty(LOG_FILE_SIZE_LIMIT)).isEqualTo(this.getMaxLogFileSize());
        }
        for (String jar : this.getJarNames()) {
            DeployedJar deployedJar = ClassPathLoader.getLatest().getJarDeployer().findDeployedJar(jar);
            assertThat(deployedJar).isNotNull();
            assertThat(Class.forName(nameOfClassContainedInJar(jar), true, new URLClassLoader(new URL[] { deployedJar.getFileURL() }))).isNotNull();
        }
        // If we have extra jars on disk left over from undeploy, make sure they aren't used
        Set<String> undeployedJarNames = new HashSet<>(actualJarNames);
        undeployedJarNames.removeAll(expectedJarNames);
        for (String jar : undeployedJarNames) {
            System.out.println("Verifying undeployed jar: " + jar);
            DeployedJar undeployedJar = ClassPathLoader.getLatest().getJarDeployer().findDeployedJar(jar);
            assertThat(undeployedJar).isNull();
        }
    });
}
Also used : ClassPathLoader(org.apache.geode.internal.ClassPathLoader) StringUtils(org.apache.commons.lang.StringUtils) Arrays(java.util.Arrays) ClusterConfigurationService(org.apache.geode.distributed.internal.ClusterConfigurationService) DeployedJar(org.apache.geode.internal.DeployedJar) Locator(org.apache.geode.test.dunit.rules.Locator) URL(java.net.URL) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Cache(org.apache.geode.cache.Cache) URLClassLoader(java.net.URLClassLoader) Collectors.toSet(java.util.stream.Collectors.toSet) Properties(java.util.Properties) Set(java.util.Set) Server(org.apache.geode.test.dunit.rules.Server) Collectors(java.util.stream.Collectors) File(java.io.File) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) LocatorServerStartupRule(org.apache.geode.test.dunit.rules.LocatorServerStartupRule) Serializable(java.io.Serializable) List(java.util.List) Stream(java.util.stream.Stream) MemberVM(org.apache.geode.test.dunit.rules.MemberVM) LOG_FILE_SIZE_LIMIT(org.apache.geode.distributed.ConfigurationProperties.LOG_FILE_SIZE_LIMIT) Configuration(org.apache.geode.management.internal.configuration.domain.Configuration) Collections(java.util.Collections) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) DeployedJar(org.apache.geode.internal.DeployedJar) URLClassLoader(java.net.URLClassLoader) Properties(java.util.Properties) URL(java.net.URL) Cache(org.apache.geode.cache.Cache) HashSet(java.util.HashSet)

Aggregations

Server (org.apache.geode.test.dunit.rules.Server)3 Properties (java.util.Properties)2 Cache (org.apache.geode.cache.Cache)2 Locator (org.apache.geode.test.dunit.rules.Locator)2 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)2 Test (org.junit.Test)2 File (java.io.File)1 Serializable (java.io.Serializable)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 Stream (java.util.stream.Stream)1 ZipFile (java.util.zip.ZipFile)1