Search in sources :

Example 6 with MemberVM

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

the class ClusterConfigDeployJarDUnitTest method testDeployToMultipleLocators.

@Test
public void testDeployToMultipleLocators() throws Exception {
    MemberVM locator = lsRule.startLocatorVM(0, locatorProps);
    locatorProps.setProperty(LOCATORS, "localhost[" + locator.getPort() + "]");
    MemberVM locator2 = lsRule.startLocatorVM(1, locatorProps);
    locatorProps.setProperty(LOCATORS, "localhost[" + locator.getPort() + "],localhost[" + locator2.getPort() + "]");
    MemberVM locator3 = lsRule.startLocatorVM(2, locatorProps);
    // has to start a server in order to run deploy command
    lsRule.startServerVM(3, serverProps, locator.getPort());
    gfshConnector.connect(locator);
    assertThat(gfshConnector.isConnected()).isTrue();
    gfshConnector.executeAndVerifyCommand("deploy --jar=" + clusterJar);
    ConfigGroup cluster = new ConfigGroup("cluster").jars("cluster.jar");
    ClusterConfig expectedClusterConfig = new ClusterConfig(cluster);
    expectedClusterConfig.verify(locator);
    expectedClusterConfig.verify(locator2);
    expectedClusterConfig.verify(locator3);
}
Also used : MemberVM(org.apache.geode.test.dunit.rules.MemberVM) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 7 with MemberVM

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

the class ClusterConfigDeployJarDUnitTest method testUndeployWithServerBounce.

@Test
public void testUndeployWithServerBounce() throws Exception {
    // set up the locator/servers
    MemberVM locator = lsRule.startLocatorVM(0, locatorProps);
    serverProps.setProperty(GROUPS, "group1");
    MemberVM server1 = lsRule.startServerVM(1, serverProps, locator.getPort());
    serverProps.setProperty(GROUPS, "group2");
    MemberVM server2 = lsRule.startServerVM(2, serverProps, locator.getPort());
    serverProps.setProperty(GROUPS, "group1,group2");
    serverProps.setProperty(LOG_LEVEL, "info");
    MemberVM server3 = lsRule.startServerVM(3, serverProps, locator.getPort());
    ConfigGroup cluster = new ConfigGroup("cluster");
    ConfigGroup group1 = new ConfigGroup("group1");
    ConfigGroup group2 = new ConfigGroup("group2");
    ClusterConfig expectedClusterConfig = new ClusterConfig(cluster);
    ClusterConfig server1Config = new ClusterConfig(cluster, group1);
    ClusterConfig server2Config = new ClusterConfig(cluster, group2);
    ClusterConfig server3Config = new ClusterConfig(cluster, group1, group2);
    gfshConnector.connect(locator);
    assertThat(gfshConnector.isConnected()).isTrue();
    gfshConnector.executeAndVerifyCommand("deploy --jar=" + clusterJar);
    // deploy cluster.jar to the cluster
    cluster.addJar("cluster.jar");
    expectedClusterConfig.verify(locator);
    expectedClusterConfig.verify(server1);
    expectedClusterConfig.verify(server2);
    expectedClusterConfig.verify(server3);
    // deploy group1.jar to both group1 and group2
    gfshConnector.executeAndVerifyCommand("deploy --jar=" + group1Jar + " --group=group1,group2");
    group1.addJar("group1.jar");
    group2.addJar("group1.jar");
    server3Config.verify(locator);
    server1Config.verify(server1);
    server2Config.verify(server2);
    server3Config.verify(server3);
    server3.getVM().bounce();
    // test undeploy cluster
    gfshConnector.executeAndVerifyCommand("undeploy --jar=cluster.jar");
    server3 = lsRule.startServerVM(3, serverProps, locator.getPort());
    cluster = cluster.removeJar("cluster.jar");
    server3Config.verify(locator);
    server1Config.verify(server1);
    server2Config.verify(server2);
    server3Config.verify(server3);
    gfshConnector.executeAndVerifyCommand("undeploy --jar=group1.jar --group=group1");
    group1 = group1.removeJar("group1.jar");
    /*
     * TODO: GEODE-2779 This is the current (weird) behavior If you started server4 with
     * group1,group2 after this undeploy command, it would have group1.jar (brought from
     * cluster_config/group2/group1.jar on locator) whereas server3 (also in group1,group2) does not
     * have this jar.
     */
    ClusterConfig weirdServer3Config = new ClusterConfig(cluster, group1, new ConfigGroup(group2).removeJar("group1.jar"));
    server3Config.verify(locator);
    server1Config.verify(server1);
    server2Config.verify(server2);
    weirdServer3Config.verify(server3);
}
Also used : MemberVM(org.apache.geode.test.dunit.rules.MemberVM) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 8 with MemberVM

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

the class ClusterConfigDeployJarDUnitTest method testDeploy.

@Test
public void testDeploy() throws Exception {
    // set up the locator/servers
    MemberVM locator = lsRule.startLocatorVM(0, locatorProps);
    // server1 in no group
    MemberVM server1 = lsRule.startServerVM(1, serverProps, locator.getPort());
    // server2 in group1
    serverProps.setProperty(GROUPS, "group1");
    MemberVM server2 = lsRule.startServerVM(2, serverProps, locator.getPort());
    // server3 in group1 and group2
    serverProps.setProperty(GROUPS, "group1,group2");
    MemberVM server3 = lsRule.startServerVM(3, serverProps, locator.getPort());
    gfshConnector.connect(locator);
    assertThat(gfshConnector.isConnected()).isTrue();
    gfshConnector.executeAndVerifyCommand("deploy --jar=" + clusterJar);
    ConfigGroup cluster = new ConfigGroup("cluster").jars("cluster.jar");
    ClusterConfig expectedClusterConfig = new ClusterConfig(cluster);
    expectedClusterConfig.verify(locator);
    expectedClusterConfig.verify(server1);
    expectedClusterConfig.verify(server2);
    expectedClusterConfig.verify(server3);
    gfshConnector.executeAndVerifyCommand("deploy --jar=" + group1Jar + " --group=group1");
    ConfigGroup group1 = new ConfigGroup("group1").jars("group1.jar");
    ClusterConfig expectedGroup1Config = new ClusterConfig(cluster, group1);
    expectedGroup1Config.verify(locator);
    expectedClusterConfig.verify(server1);
    expectedGroup1Config.verify(server2);
    expectedGroup1Config.verify(server3);
    gfshConnector.executeAndVerifyCommand("deploy --jar=" + group2Jar + " --group=group2");
    ConfigGroup group2 = new ConfigGroup("group2").jars("group2.jar");
    ClusterConfig expectedGroup1and2Config = new ClusterConfig(cluster, group1, group2);
    expectedGroup1and2Config.verify(locator);
    expectedClusterConfig.verify(server1);
    expectedGroup1Config.verify(server2);
    expectedGroup1and2Config.verify(server3);
}
Also used : MemberVM(org.apache.geode.test.dunit.rules.MemberVM) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 9 with MemberVM

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

the class ClusterConfigImportDUnitTest method testExportClusterConfig.

public void testExportClusterConfig(String zipFilePath) throws Exception {
    MemberVM server1 = lsRule.startServerVM(1, serverProps, locatorVM.getPort());
    gfshConnector.executeAndVerifyCommand("create region --name=myRegion --type=REPLICATE");
    ConfigGroup cluster = new ConfigGroup("cluster").regions("myRegion");
    ClusterConfig expectedClusterConfig = new ClusterConfig(cluster);
    expectedClusterConfig.verify(server1);
    expectedClusterConfig.verify(locatorVM);
    gfshConnector.executeAndVerifyCommand("export cluster-configuration --zip-file-name=" + zipFilePath);
    File exportedZip = new File(zipFilePath);
    assertThat(exportedZip).exists();
    Set<String> actualZipEnries = new ZipFile(exportedZip).stream().map(ZipEntry::getName).collect(Collectors.toSet());
    ConfigGroup exportedClusterGroup = cluster.configFiles("cluster.xml", "cluster.properties");
    ClusterConfig expectedExportedClusterConfig = new ClusterConfig(exportedClusterGroup);
    Set<String> expectedZipEntries = new HashSet<>();
    for (ConfigGroup group : expectedExportedClusterConfig.getGroups()) {
        String groupDir = group.getName() + File.separator;
        for (String jarOrXmlOrPropFile : group.getAllFiles()) {
            expectedZipEntries.add(groupDir + jarOrXmlOrPropFile);
        }
    }
    assertThat(actualZipEnries).isEqualTo(expectedZipEntries);
}
Also used : ZipFile(java.util.zip.ZipFile) MemberVM(org.apache.geode.test.dunit.rules.MemberVM) File(java.io.File) ZipFile(java.util.zip.ZipFile) HashSet(java.util.HashSet)

Example 10 with MemberVM

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

the class ClusterConfigImportDUnitTest method testImportWithRunningServerWithRegion.

@Test
public void testImportWithRunningServerWithRegion() throws Exception {
    MemberVM server1 = lsRule.startServerVM(1, serverProps, locatorVM.getPort());
    // create another server as well
    MemberVM server2 = lsRule.startServerVM(2, serverProps, locatorVM.getPort());
    String regionName = "regionA";
    server1.invoke(() -> {
        // this region will be created on both servers, but we should only be getting the name once.
        Cache cache = LocatorServerStartupRule.serverStarter.getCache();
        cache.createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
    });
    CommandResult result = gfshConnector.executeCommand("import cluster-configuration --zip-file-name=" + clusterConfigZipPath);
    assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
    assertThat(result.getContent().toString()).contains("existing regions: " + regionName);
}
Also used : MemberVM(org.apache.geode.test.dunit.rules.MemberVM) Cache(org.apache.geode.cache.Cache) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

MemberVM (org.apache.geode.test.dunit.rules.MemberVM)27 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)19 Test (org.junit.Test)19 Properties (java.util.Properties)8 File (java.io.File)5 ZipFile (java.util.zip.ZipFile)3 Cache (org.apache.geode.cache.Cache)3 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)3 HashSet (java.util.HashSet)2 LuceneIndex (org.apache.geode.cache.lucene.LuceneIndex)2 LuceneService (org.apache.geode.cache.lucene.LuceneService)2 ClusterConfigurationService (org.apache.geode.distributed.internal.ClusterConfigurationService)2 InternalLocator (org.apache.geode.distributed.internal.InternalLocator)2 CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)2 Before (org.junit.Before)2 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 Serializable (java.io.Serializable)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1