From e769796c5611f4fad1a21869ddea29853ed1958e Mon Sep 17 00:00:00 2001 From: Jared Stewart Date: Mon, 6 Feb 2017 14:54:49 -0800 Subject: [PATCH] GEODE-2430: Remove jar and zip files from test resources This closes #393 --- .../configuration/ClusterConfigBaseTest.java | 69 +++++++++++++++++- .../ClusterConfigDeployJarDUnitTest.java | 13 +++- .../ClusterConfigImportDUnitTest.java | 8 +- .../ClusterConfigStartMemberDUnitTest.java | 2 +- .../ClusterConfigWithSecurityDUnitTest.java | 31 +++++--- .../internal/configuration/cluster.jar | Bin 617 -> 0 bytes .../internal/configuration/cluster_config.zip | Bin 4172 -> 0 bytes .../configuration/cluster_config_security.zip | Bin 950 -> 0 bytes .../internal/configuration/group1.jar | Bin 617 -> 0 bytes .../internal/configuration/group2.jar | Bin 617 -> 0 bytes 10 files changed, 100 insertions(+), 23 deletions(-) delete mode 100755 geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster.jar delete mode 100644 geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster_config.zip delete mode 100644 geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster_config_security.zip delete mode 100755 geode-core/src/test/resources/org/apache/geode/management/internal/configuration/group1.jar delete mode 100755 geode-core/src/test/resources/org/apache/geode/management/internal/configuration/group2.jar diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java index 063293573265..3a3c74cd9d10 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java @@ -18,18 +18,22 @@ import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION; import static org.apache.geode.distributed.ConfigurationProperties.USE_CLUSTER_CONFIGURATION; +import static org.assertj.core.api.Assertions.assertThat; +import org.apache.commons.io.FileUtils; +import org.apache.geode.internal.ClassBuilder; +import org.apache.geode.management.internal.configuration.utils.ZipUtils; import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase; import org.apache.geode.test.dunit.rules.LocatorServerStartupRule; import org.junit.Before; import org.junit.Rule; +import java.io.File; +import java.io.IOException; import java.util.Properties; public class ClusterConfigBaseTest extends JUnit4DistributedTestCase { - public static final String CLUSTER_CONFIG_ZIP_FILENAME = "cluster_config.zip"; - public static final String CLUSTER_CONFIG_ZIP_PATH = - ClusterConfigBaseTest.class.getResource(CLUSTER_CONFIG_ZIP_FILENAME).getPath(); + public String clusterConfigZipPath; public static final ConfigGroup CLUSTER = new ConfigGroup("cluster").regions("regionForCluster") .jars("cluster.jar").maxLogFileSize("5000").configFiles("cluster.properties", "cluster.xml"); @@ -56,6 +60,7 @@ public class ClusterConfigBaseTest extends JUnit4DistributedTestCase { @Before public void before() throws Exception { + clusterConfigZipPath = buildClusterZipFile(); locatorProps = new Properties(); serverProps = new Properties(); @@ -63,4 +68,62 @@ public void before() throws Exception { locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true"); serverProps.setProperty(USE_CLUSTER_CONFIGURATION, "true"); } + + private String buildClusterZipFile() throws Exception { + ClassBuilder classBuilder = new ClassBuilder(); + File clusterConfigDir = this.lsRule.getTempFolder().newFolder("cluster_config"); + + File clusterDir = new File(clusterConfigDir, "cluster"); + String clusterXml = "\n" + + "\n" + + "\n" + + " \n" + + " \n" + "\n"; + writeFile(clusterDir, "cluster.xml", clusterXml); + writeFile(clusterDir, "cluster.properties", "log-file-size-limit=5000"); + createJarFileWithClass("Cluster", "cluster.jar", clusterDir); + + File group1Dir = new File(clusterConfigDir, "group1"); + String group1Xml = "\n" + + "\n" + + "\n" + + " \n" + + " \n" + "\n"; + writeFile(group1Dir, "group1.xml", group1Xml); + writeFile(group1Dir, "group1.properties", "log-file-size-limit=6000"); + createJarFileWithClass("Group1", "group1.jar", group1Dir); + + + File group2Dir = new File(clusterConfigDir, "group2"); + String group2Xml = "\n" + + "\n" + + "\n" + + " \n" + + " \n" + "\n"; + writeFile(group2Dir, "group1.xml", group2Xml); + writeFile(group2Dir, "group2.properties", "log-file-size-limit=7000"); + createJarFileWithClass("Group2", "group2.jar", group2Dir); + + + File clusterConfigZip = lsRule.getTempFolder().newFile("cluster_config.zip"); + ZipUtils.zipDirectory(clusterConfigDir.getCanonicalPath(), clusterConfigZip.getCanonicalPath()); + + FileUtils.deleteDirectory(clusterConfigDir); + return clusterConfigZip.getCanonicalPath(); + } + + private File writeFile(File dir, String fileName, String content) throws IOException { + dir.mkdirs(); + File file = new File(dir, fileName); + FileUtils.writeStringToFile(file, content); + + return file; + } + + protected String createJarFileWithClass(String className, String jarName, File dir) + throws IOException { + File jarFile = new File(dir, jarName); + new ClassBuilder().writeJarFromName(className, jarFile); + return jarFile.getCanonicalPath(); + } } diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java index 06e969c2cf76..79f0128ecb87 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java @@ -19,6 +19,7 @@ import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS; import static org.assertj.core.api.Assertions.assertThat; +import org.apache.geode.internal.ClassBuilder; import org.apache.geode.management.cli.Result; import org.apache.geode.management.internal.cli.result.CommandResult; import org.apache.geode.test.dunit.rules.GfshShellConnectionRule; @@ -30,6 +31,9 @@ import org.junit.Test; import org.junit.experimental.categories.Category; +import java.io.File; +import java.io.IOException; + @Category(DistributedTest.class) public class ClusterConfigDeployJarDUnitTest extends ClusterConfigBaseTest { private GfshShellConnectionRule gfshConnector; @@ -39,9 +43,10 @@ public class ClusterConfigDeployJarDUnitTest extends ClusterConfigBaseTest { @Before public void before() throws Exception { super.before(); - clusterJar = getClass().getResource("cluster.jar").getPath(); - group1Jar = getClass().getResource("group1.jar").getPath(); - group2Jar = getClass().getResource("group2.jar").getPath(); + + clusterJar = createJarFileWithClass("Cluster", "cluster.jar", lsRule.getTempFolder().getRoot()); + group1Jar = createJarFileWithClass("Group1", "group1.jar", lsRule.getTempFolder().getRoot()); + group2Jar = createJarFileWithClass("Group2", "group2.jar", lsRule.getTempFolder().getRoot()); } @After @@ -53,7 +58,7 @@ public void after() throws Exception { @Test public void testDeployToNoServer() throws Exception { - String clusterJarPath = getClass().getResource("cluster.jar").getPath(); + String clusterJarPath = clusterJar; // set up the locator/servers Locator locator = lsRule.startLocatorVM(0, locatorProps); diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java index d8b4cb365613..f68015e5e4f7 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java @@ -83,7 +83,7 @@ public void testImportWithRunningServerWithData() throws Exception { }); CommandResult result = gfshConnector - .executeCommand("import cluster-configuration --zip-file-name=" + CLUSTER_CONFIG_ZIP_PATH); + .executeCommand("import cluster-configuration --zip-file-name=" + clusterConfigZipPath); assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR); assertThat(result.getContent().toString()).contains("existing data in regions: " + regionName); @@ -105,7 +105,7 @@ public void testImportWithRunningServer() throws Exception { // even though we have a region recreated, we can still import since there is no data // in the region CommandResult result = gfshConnector - .executeCommand("import cluster-configuration --zip-file-name=" + CLUSTER_CONFIG_ZIP_PATH); + .executeCommand("import cluster-configuration --zip-file-name=" + clusterConfigZipPath); assertThat(result.getStatus()).isEqualTo(Result.Status.OK) .describedAs(result.getContent().toString()); @@ -130,7 +130,7 @@ public void testImportWithRunningServer() throws Exception { @Test public void testImportClusterConfig() throws Exception { CommandResult result = gfshConnector - .executeCommand("import cluster-configuration --zip-file-name=" + CLUSTER_CONFIG_ZIP_PATH); + .executeCommand("import cluster-configuration --zip-file-name=" + clusterConfigZipPath); assertThat(result.getStatus()).isEqualTo(Result.Status.OK); // Make sure that a backup of the old clusterConfig was created @@ -164,7 +164,7 @@ public void testImportWithMultipleLocators() throws Exception { Locator locator2 = lsRule.startLocatorVM(2, locatorProps); CommandResult result = gfshConnector - .executeCommand("import cluster-configuration --zip-file-name=" + CLUSTER_CONFIG_ZIP_PATH); + .executeCommand("import cluster-configuration --zip-file-name=" + clusterConfigZipPath); assertThat(result.getStatus()).isEqualTo(Result.Status.OK); CONFIG_FROM_ZIP.verify(locator); diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigStartMemberDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigStartMemberDUnitTest.java index fb4aa54fb7f7..c0d22bfc697e 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigStartMemberDUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigStartMemberDUnitTest.java @@ -89,7 +89,7 @@ private Locator startLocatorWithLoadCCFromDir() throws Exception { // tempFolder/locator-0/cluster_config/cluster/cluster.jar // tempFolder/locator-0/cluster_config/group1/ {group1.xml, group1.properties, group1.jar} // tempFolder/locator-0/cluster_config/group2/ ... - ZipUtils.unzip(CLUSTER_CONFIG_ZIP_PATH, configDir.getCanonicalPath()); + ZipUtils.unzip(clusterConfigZipPath, configDir.getCanonicalPath()); Properties properties = new Properties(); properties.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true"); diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigWithSecurityDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigWithSecurityDUnitTest.java index 995e18edfa09..388fd9d40cca 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigWithSecurityDUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigWithSecurityDUnitTest.java @@ -21,9 +21,11 @@ import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANAGER; import static org.assertj.core.api.Assertions.assertThat; +import org.apache.commons.io.FileUtils; import org.apache.geode.distributed.internal.ClusterConfigurationService; import org.apache.geode.distributed.internal.InternalLocator; import org.apache.geode.management.internal.cli.i18n.CliStrings; +import org.apache.geode.management.internal.configuration.utils.ZipUtils; import org.apache.geode.security.SimpleTestSecurityManager; import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase; import org.apache.geode.test.dunit.rules.GfshShellConnectionRule; @@ -37,20 +39,12 @@ import org.junit.Test; import org.junit.experimental.categories.Category; +import java.io.File; import java.util.Properties; @Category({DistributedTest.class, SecurityTest.class}) public class ClusterConfigWithSecurityDUnitTest extends JUnit4DistributedTestCase { - - // the zip file is under test/resource/org/apache/geode/management/internal/configuration - // it only contains cluster.properites whose content is - // mcast-port=0 - // log-file-size-limit=8000 - // security-manager=org.apache.geode.example.security.ExampleSecurityManager - - public static final String CLUSTER_CONFIG_ZIP_FILENAME = "cluster_config_security.zip"; - public static final String CLUSTER_CONFIG_ZIP_PATH = - ClusterConfigBaseTest.class.getResource(CLUSTER_CONFIG_ZIP_FILENAME).getPath(); + public String clusterConfigZipPath; @Rule public LocatorServerStartupRule lsRule = new LocatorServerStartupRule(); @@ -60,6 +54,8 @@ public class ClusterConfigWithSecurityDUnitTest extends JUnit4DistributedTestCas @Before public void before() throws Exception { + clusterConfigZipPath = buildSecureClusterConfigZip(); + locatorProps = new Properties(); locatorProps.setProperty(SECURITY_MANAGER, SimpleTestSecurityManager.class.getName()); locator0 = lsRule.startLocatorVM(0, locatorProps); @@ -92,7 +88,7 @@ public void testImportNotOverwriteSecurity() throws Exception { "cluster"); connector.executeAndVerifyCommand( - "import cluster-configuration --zip-file-name=" + CLUSTER_CONFIG_ZIP_PATH); + "import cluster-configuration --zip-file-name=" + clusterConfigZipPath); locator0.invoke(() -> { InternalLocator locator = LocatorServerStartupRule.locatorStarter.locator; @@ -106,4 +102,17 @@ public void testImportNotOverwriteSecurity() throws Exception { .isEqualTo(SimpleTestSecurityManager.class.getName()); }); } + + private String buildSecureClusterConfigZip() throws Exception { + File clusterDir = lsRule.getTempFolder().newFolder("cluster"); + File clusterSubDir = new File(clusterDir, "cluster"); + + String clusterProperties = "mcast-port=0\n" + "log-file-size-limit=8000\n" + + "security-manager=org.apache.geode.example.security.ExampleSecurityManager"; + FileUtils.writeStringToFile(new File(clusterSubDir, "cluster.properties"), clusterProperties); + File clusterZip = new File(lsRule.getTempFolder().getRoot(), "cluster_config_security.zip"); + ZipUtils.zipDirectory(clusterDir.getCanonicalPath(), clusterZip.getCanonicalPath()); + FileUtils.deleteDirectory(clusterDir); + return clusterZip.getCanonicalPath(); + } } diff --git a/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster.jar b/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster.jar deleted file mode 100755 index 9c9541db93283ff571994e8a9e99d2d33beb2364..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 617 zcmWIWW@h1HVBp|jC<|!wWB>vt5CH_7K6 ziy$lXb@cOea}5sB^L6{|d*-x{x31nrUT z{IQ6h(Y7b-|3w280zWX;h@85YI590<-gxtF`~C6v8PY7eA1HAah#We&v0qqzIZxef z@0GWvDW1IkD0a!x6=9n1rDE6SN$%OXu4H?HM0}jChO|8AXvh7dPP965+9oK7>ukJOwQnBF94Cy2mj+Z9?=A@R- zIsV~6uw{V6vfa+|-CHNg>b+2%zHdoto6pUTqN0Tofm4NyoWB1O&PhIAEn<6n$y<@f z_DtUj9V8My>Dz4=PEudY-(w!OF?hCXaCdujfHxzP2s7>o0)`e42r#^L1kv#5Le_>Y xx2(1)@&61V~$0vjfXab(Bti%lcj|RngaDax%sH)YYKzB0+MQ!=3QJ!j~!MnS)*R_T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T}TqWkPMHuIMht7T*~id6+ZqN9b=o&K?tzukJ_!AgDRN2EEJz)Hyf94 zu!;_O)EnU~&|$lV4j>I3k)na3q(+$}6ssdC{;nz#s&>E5Ue`jJqp6rN)dDUkIIlwi zy@vPV+Pm-(4JR++j(udLp+o+l@x(eh7#JbItyc~(fSn5Q)k|YillHlOhN1qpc7{1( zKvP&h!O$J2C>7`UHNl5pT+2nxwR&3fu-NKHYV7! zh32Zcz+cwcPYG^aFBbX)HMN-l>kHer%SAuGchU=>L)Hc8m$$9|7;WIwk6xY)QfSbZ zT-KyEmx?z2>B~jL!i>f42)2hGMp sRZ=_qN#pbA`>{gNKT;c$Gi3W(aZ{m~soeok`^6484Fmx0tv+;r19$ihY5)KL diff --git a/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster_config_security.zip b/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster_config_security.zip deleted file mode 100644 index c09114e2437ed95d6577490eb94ebc6f6c4dde1c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 950 zcmWIWW@h1H00GVdLoYA`N^md;FeK-c7MG+J>4!$}FoaF6i}(b@Ul~Oh0)V*wFc_ zihJvvlRlp=Sxt@Ey;<#cI?5VicPy-JmC;aP7qB_Pe@Am;Oi6ifj_Jxpn++E1hcw;G-IKv zK=Y5)k{wKaii(Z_Y97aB6rQ;UAL2Qq@`v{NY09mngI$Wc8&t6-UG3~5L*onHAW^;W?adG2dDxJ9Ns#DXhbM*z!OV= zH^>A;7$C=q6a&J9C5>iCCSVH&4tT-ZdKCQ{sTFu)=QpAmv6M#wQD r8G-CWRHG0+L=HbyB%_uz#$q!Hdz>SCmX!?@xU4|f3^YKN3B&^ctxW9# diff --git a/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/group1.jar b/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/group1.jar deleted file mode 100755 index fa105ab50d219aa00d144fb2fee40440f0538cc7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 617 zcmWIWW@h1HVBp|j@C<14WB>vt5CH_7KE;?7qUY=O+4sz8A8%c~i@e^tTIbH3-yCFc#rVO~M^Bm14C~>qjbvbCV8{Ss z9-v|FMfs%#hI+|4iN(dP{yY5+JBZAg{-aOvV2rGgY=D5`MZt>^4#|#*9{c0M5|xvc z<^P1cG`bvQ{}9-*z075n`TH3&=l=cq_ZM41=V1mjCH~!ZI&XH~C@*v zva8(itn0=Z%Y2u19~C_~^QDvd^_GVxU(QK5`gF5Wk8tdY-``AwuP#1OlzL>T$j_LN zTW4M`y}BpE?AxT>t8(t^-8eVg tfhCQaKoYJEDfZA!K#wG_cCZO$KoU910=!w-K(fq0xEV+<07feV0{~i1zhwXb diff --git a/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/group2.jar b/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/group2.jar deleted file mode 100755 index b251f0d052c2d5a68ae0e4095a288a879eb062c8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 617 zcmWIWW@h1HVBp|jhzV%(WB>vt5CH_7K6 ziy$lXb@cOea}5sB^L6{|d*-x{x31nrUTR#5_R5+>7!{3yk!Va}tY-UHy0Z9d;0zGyO-O;=veMA=v-{&WnNX3qWl^Y1UVg3iMXW=j0K?R4Jkyis20Q1Cj; zEA)DcMr2pH;aS&>GnV--?LI1caOO)V^Xn}SPrjU!aP;YBr5@qf6~Dik247u#qA2yq zQjwoAA-B%FUV3#;hS|4CyI1Ah*Sm3U_Q{%Di6yDgo~5gKi?0};^KBB4tKpkwcl4w0 zthRy&MHA*Z&d3R}OYv5fmib(t^H1rZdCWVuJDWMLH!RmwHoTQSe?e%uTw&=hRmCS# z-&k@IXJ0)0BfjQJ>