From 6d8f77f044d0ad236f80750c243d44e793e2b599 Mon Sep 17 00:00:00 2001 From: Ji Sun Date: Wed, 20 Nov 2019 22:36:37 -0800 Subject: [PATCH] SDC-12952. Test failures introduced by changes to RuntimeInfo Change-Id: I1b659d8fffae75066d4e4556c7d99065056a9370 Reviewed-on: https://review.streamsets.net/c/datacollector/+/27758 Reviewed-by: Jeff Evans Tested-by: StreamSets CI --- .../datacollector/main/TestRuntimeInfo.java | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/container/src/test/java/com/streamsets/datacollector/main/TestRuntimeInfo.java b/container/src/test/java/com/streamsets/datacollector/main/TestRuntimeInfo.java index ccac8958c28..c12888fa792 100644 --- a/container/src/test/java/com/streamsets/datacollector/main/TestRuntimeInfo.java +++ b/container/src/test/java/com/streamsets/datacollector/main/TestRuntimeInfo.java @@ -57,7 +57,7 @@ public void cleanUp() { System.getProperties().remove(RuntimeModule.SDC_PROPERTY_PREFIX + RuntimeInfo.DATA_DIR); System.getProperties().remove(RuntimeModule.SDC_PROPERTY_PREFIX + RuntimeInfo.STATIC_WEB_DIR); System.getProperties().remove(RuntimeModule.SDC_PROPERTY_PREFIX + RuntimeInfo.RESOURCES_DIR); - System.getProperties().remove(RuntimeInfo.getBaseHttpUrlAttr(RuntimeInfo.SDC_PRODUCT)); + System.getProperties().remove(String.format(RuntimeInfo.BASE_HTTP_URL_ATTR, RuntimeInfo.SDC_PRODUCT)); } @Test @@ -122,8 +122,7 @@ public void testConfigIdAndBaseHttpUrl() throws Exception { Assert.assertTrue(dir.mkdirs()); System.setProperty(RuntimeModule.SDC_PROPERTY_PREFIX + RuntimeInfo.CONFIG_DIR, dir.getAbsolutePath()); Properties props = new Properties(); - final String productName = "sdc"; - props.setProperty(String.format(RuntimeInfo.BASE_HTTP_URL_ATTR, productName), "HTTP"); + props.setProperty(String.format(RuntimeInfo.BASE_HTTP_URL_ATTR, RuntimeInfo.SDC_PRODUCT), "HTTP"); props.setProperty(RemoteSSOService.SECURITY_SERVICE_APP_AUTH_TOKEN_CONFIG, "AUTH_TOKEN"); props.setProperty(RemoteSSOService.DPM_ENABLED, "true"); props.setProperty(RemoteSSOService.DPM_DEPLOYMENT_ID, "foo"); @@ -142,26 +141,31 @@ public void testConfigIdAndBaseHttpUrl() throws Exception { @Test public void testTransformerRuntimeInfoConfigAndId() throws Exception { final String productName = "transformer"; - System.setProperty(productName + RuntimeInfo.STATIC_WEB_DIR, "target/w"); - System.setProperty(productName + RuntimeInfo.CONFIG_DIR, "target/x"); - System.setProperty(productName + RuntimeInfo.LOG_DIR, "target/y"); System.setProperty(productName + RuntimeInfo.DATA_DIR, "target/z"); - System.setProperty(productName + RuntimeInfo.RESOURCES_DIR, "target/R"); - File dir = new File("target", UUID.randomUUID().toString()); - Assert.assertTrue(dir.mkdirs()); - System.setProperty(productName + RuntimeInfo.CONFIG_DIR, dir.getAbsolutePath()); - Properties props = new Properties(); - props.setProperty(String.format(RuntimeInfo.BASE_HTTP_URL_ATTR, productName), "HTTP"); - Writer writer = new FileWriter(new File(dir, productName + ".properties")); - props.store(writer, ""); - writer.close(); - RuntimeModule.setProductName(productName); - RuntimeModule.setPropertyPrefix(productName); - ObjectGraph og = ObjectGraph.create(RuntimeModule.class); - og.get(Configuration.class); - RuntimeInfo info = og.get(RuntimeInfo.class); - Assert.assertEquals("HTTP", info.getBaseHttpUrl()); + try { + File dir = new File("target", UUID.randomUUID().toString()); + Assert.assertTrue(dir.mkdirs()); + System.setProperty(productName + RuntimeInfo.CONFIG_DIR, dir.getAbsolutePath()); + Properties props = new Properties(); + props.setProperty(String.format(RuntimeInfo.BASE_HTTP_URL_ATTR, productName), "HTTP"); + Writer writer = new FileWriter(new File(dir, productName + ".properties")); + props.store(writer, ""); + writer.close(); + RuntimeModule.setProductName(productName); + RuntimeModule.setPropertyPrefix(productName); + ObjectGraph og = ObjectGraph.create(RuntimeModule.class); + og.get(Configuration.class); + RuntimeInfo info = og.get(RuntimeInfo.class); + Assert.assertEquals("HTTP", info.getBaseHttpUrl()); + } finally { + // set productName back to default value of SDC + RuntimeModule.setProductName(RuntimeInfo.SDC_PRODUCT); + RuntimeModule.setPropertyPrefix(RuntimeInfo.SDC_PRODUCT); + // Clean up the system properties set for the transformer + System.getProperties().remove(productName + RuntimeInfo.DATA_DIR); + System.getProperties().remove(productName + RuntimeInfo.CONFIG_DIR); + } } @Test @@ -170,7 +174,7 @@ public void testSlaveRuntimeInfoConfigAndId() throws Exception { Assert.assertTrue(dir.mkdirs()); System.setProperty(RuntimeModule.SDC_PROPERTY_PREFIX + RuntimeInfo.CONFIG_DIR, dir.getAbsolutePath()); Properties props = new Properties(); - props.setProperty(RuntimeInfo.getBaseHttpUrlAttr(RuntimeInfo.SDC_PRODUCT), "HTTP"); + props.setProperty(String.format(RuntimeInfo.BASE_HTTP_URL_ATTR, RuntimeInfo.SDC_PRODUCT), "HTTP"); props.setProperty(ClusterModeConstants.CLUSTER_PIPELINE_REMOTE, "true"); props.setProperty(RemoteSSOService.SECURITY_SERVICE_APP_AUTH_TOKEN_CONFIG, "AUTH_TOKEN"); props.setProperty(RemoteSSOService.DPM_ENABLED, "true");