Repository: incubator-tamaya-sandbox Updated Branches: refs/heads/master 2679548b0 -> f96cbd03d
TAMAYA-291: Rework ETCd tests Fix warnings and minor typos. Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/f96cbd03 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/f96cbd03 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/f96cbd03 Branch: refs/heads/master Commit: f96cbd03d4197282f95f6f4c7e1562d1127ac4de Parents: 2679548 Author: Phil Ottlinger <[email protected]> Authored: Tue Nov 7 06:36:37 2017 +0100 Committer: Phil Ottlinger <[email protected]> Committed: Tue Nov 7 06:36:37 2017 +0100 ---------------------------------------------------------------------- .../org/apache/tamaya/etcd/EtcdAccessor.java | 5 ++-- .../apache/tamaya/etcd/EtcdBackendConfig.java | 17 ++++++----- .../apache/tamaya/etcd/EtcdPropertySource.java | 8 +++--- .../apache/tamaya/etcd/EtcdAccessorTest.java | 30 ++++++++++---------- .../tamaya/etcd/EtcdPropertySourceTest.java | 4 +-- 5 files changed, 33 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f96cbd03/etcd/src/main/java/org/apache/tamaya/etcd/EtcdAccessor.java ---------------------------------------------------------------------- diff --git a/etcd/src/main/java/org/apache/tamaya/etcd/EtcdAccessor.java b/etcd/src/main/java/org/apache/tamaya/etcd/EtcdAccessor.java index 4feccfa..62632e1 100644 --- a/etcd/src/main/java/org/apache/tamaya/etcd/EtcdAccessor.java +++ b/etcd/src/main/java/org/apache/tamaya/etcd/EtcdAccessor.java @@ -67,7 +67,7 @@ public class EtcdAccessor { private final int connectTimeout = 1000; /** - * Property that make Johnzon accept commentc. + * Property that makes Johnzon accept comments. */ public static final String JOHNZON_SUPPORTS_COMMENTS_PROP = "org.apache.johnzon.supports-comments"; /** @@ -109,7 +109,6 @@ public class EtcdAccessor { } else { serverURL = server; } - } /** @@ -327,7 +326,7 @@ public class EtcdAccessor { * </pre> * * @param key the key to be deleted. - * @return the response mpas as described above. + * @return the response maps as described above. */ public Map<String, String> delete(String key) { final Map<String, String> result = new HashMap<>(); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f96cbd03/etcd/src/main/java/org/apache/tamaya/etcd/EtcdBackendConfig.java ---------------------------------------------------------------------- diff --git a/etcd/src/main/java/org/apache/tamaya/etcd/EtcdBackendConfig.java b/etcd/src/main/java/org/apache/tamaya/etcd/EtcdBackendConfig.java index f760b21..123313a 100644 --- a/etcd/src/main/java/org/apache/tamaya/etcd/EtcdBackendConfig.java +++ b/etcd/src/main/java/org/apache/tamaya/etcd/EtcdBackendConfig.java @@ -29,21 +29,24 @@ import java.util.logging.Logger; */ public final class EtcdBackendConfig { - private static final Logger LOG = Logger.getLogger(EtcdBackendConfig.class.getName()); + private static final Logger LOG = Logger.getLogger(EtcdBackendConfig.class.getName()); + private static final String TAMAYA_ETCD_SERVER_URLS = "tamaya.etcd.server.urls"; + private static final String TAMAYA_ETCD_TIMEOUT = "tamaya.etcd.timeout"; + private static final String TAMAYA_ETCD_DISABLE = "tamaya.etcd.disable"; private static List<EtcdAccessor> etcdBackends = new ArrayList<>(); static{ int timeout = 2; - String val = System.getProperty("tamaya.etcd.timeout"); + String val = System.getProperty(TAMAYA_ETCD_TIMEOUT); if(val == null){ - val = System.getenv("tamaya.etcd.timeout"); + val = System.getenv(TAMAYA_ETCD_TIMEOUT); } if(val!=null){ timeout = Integer.parseInt(val); } - String serverURLs = System.getProperty("tamaya.etcd.server.urls"); + String serverURLs = System.getProperty(TAMAYA_ETCD_SERVER_URLS); if(serverURLs==null){ - serverURLs = System.getenv("tamaya.etcd.server.urls"); + serverURLs = System.getenv(TAMAYA_ETCD_SERVER_URLS); } if(serverURLs==null){ serverURLs = "http://127.0.0.1:4001"; @@ -61,9 +64,9 @@ public final class EtcdBackendConfig { private EtcdBackendConfig(){} private static boolean isEtcdDisabled() { - String value = System.getProperty("tamaya.etcd.disable"); + String value = System.getProperty(TAMAYA_ETCD_DISABLE); if(value==null){ - value = System.getenv("tamaya.etcd.disable"); + value = System.getenv(TAMAYA_ETCD_DISABLE); } if(value==null){ return false; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f96cbd03/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java ---------------------------------------------------------------------- diff --git a/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java b/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java index 9e55643..6531153 100644 --- a/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java +++ b/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java @@ -35,9 +35,9 @@ import java.util.logging.Logger; /** * Propertysource that is reading configuration from a configured etcd endpoint. Setting - * {@code etcd.prefix} as system property maps the etcd based onfiguration + * {@code etcd.prefix} as system property maps the etcd based configuration * to this prefix namespace. Etcd servers are configured as {@code etcd.server.urls} system or environment property. - * ETcd can be disabled by setting {@code tamaya.etcdprops.disable} either as env or system property. + * Etcd can be disabled by setting {@code tamaya.etcdprops.disable} either as environment or system property. */ public class EtcdPropertySource extends BasePropertySource implements MutablePropertySource{ @@ -130,7 +130,7 @@ public class EtcdPropertySource extends BasePropertySource return Integer.parseInt(configuredOrdinal.getValue()); } catch(Exception e){ Logger.getLogger(getClass().getName()).log(Level.WARNING, - "Configured Ordinal is not an int number: " + configuredOrdinal, e); + "Configured ordinal is not an int number: " + configuredOrdinal, e); } } return getDefaultOrdinal(); @@ -150,7 +150,7 @@ public class EtcdPropertySource extends BasePropertySource try{ props = accessor.get(key); if(!props.containsKey("_ERROR")) { - // No repfix mapping necessary here, since we only access/return the value... + // No prefix mapping necessary here, since we only access/return the value... return PropertyValue.builder(key, props.get(key), getName()).setMetaEntries(metaData) .addMetaEntries(props).removeMetaEntry(key).build(); } else{ http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f96cbd03/etcd/src/test/java/org/apache/tamaya/etcd/EtcdAccessorTest.java ---------------------------------------------------------------------- diff --git a/etcd/src/test/java/org/apache/tamaya/etcd/EtcdAccessorTest.java b/etcd/src/test/java/org/apache/tamaya/etcd/EtcdAccessorTest.java index 80bd716..3c8bff9 100644 --- a/etcd/src/test/java/org/apache/tamaya/etcd/EtcdAccessorTest.java +++ b/etcd/src/test/java/org/apache/tamaya/etcd/EtcdAccessorTest.java @@ -19,6 +19,7 @@ package org.apache.tamaya.etcd; import org.junit.BeforeClass; +import org.junit.Test; import java.net.MalformedURLException; import java.util.Map; @@ -27,7 +28,7 @@ import java.util.UUID; import static org.junit.Assert.*; /** - * Tests for th etcd backend integration. You must have set a system property so, theses tests are executed, e.g. + * Tests for the etcd backend integration. You must have set a system property so, theses tests are executed, e.g. * {@code -Detcd.url=http://127.0.0.1:4001}. */ public class EtcdAccessorTest { @@ -47,70 +48,69 @@ public class EtcdAccessorTest { } } - @org.junit.Test + @Test public void testGetVersion() throws Exception { if(!execute)return; assertEquals(accessor.getVersion(), "etcd 0.4.9"); } - @org.junit.Test + @Test public void testGet() throws Exception { if(!execute)return; Map<String,String> result = accessor.get("test1"); assertNotNull(result); } - @org.junit.Test + @Test public void testSetNormal() throws Exception { if(!execute)return; String value = UUID.randomUUID().toString(); Map<String,String> result = accessor.set("testSetNormal", value); assertNull(result.get("_testSetNormal.ttl")); - assertEquals(accessor.get("testSetNormal").get("testSetNormal"), value); + assertEquals(value, accessor.get("testSetNormal").get("testSetNormal")); } - @org.junit.Test + @Test public void testSetNormal2() throws Exception { if(!execute)return; String value = UUID.randomUUID().toString(); Map<String,String> result = accessor.set("testSetNormal2", value, null); assertNull(result.get("_testSetNormal2.ttl")); - assertEquals(accessor.get("testSetNormal2").get("testSetNormal2"), value); + assertEquals(value, accessor.get("testSetNormal2").get("testSetNormal2")); } - @org.junit.Test + @Test public void testSetWithTTL() throws Exception { if(!execute)return; String value = UUID.randomUUID().toString(); Map<String,String> result = accessor.set("testSetWithTTL", value, 1); assertNotNull(result.get("_testSetWithTTL.ttl")); - assertEquals(accessor.get("testSetWithTTL").get("testSetWithTTL"), value); + assertEquals(value, accessor.get("testSetWithTTL").get("testSetWithTTL")); Thread.sleep(2000L); result = accessor.get("testSetWithTTL"); assertNull(result.get("testSetWithTTL")); } - - @org.junit.Test + @Test public void testDelete() throws Exception { if(!execute)return; String value = UUID.randomUUID().toString(); Map<String,String> result = accessor.set("testDelete", value, null); - assertEquals(accessor.get("testDelete").get("testDelete"), value); + assertEquals(value, accessor.get("testDelete").get("testDelete")); assertNotNull(result.get("_testDelete.createdIndex")); result = accessor.delete("testDelete"); - assertEquals(result.get("_testDelete.prevNode.value"),value); + assertEquals(value, result.get("_testDelete.prevNode.value")); assertNull(accessor.get("testDelete").get("testDelete")); } - @org.junit.Test + @Test public void testGetProperties() throws Exception { if(!execute)return; String value = UUID.randomUUID().toString(); accessor.set("testGetProperties1", value); Map<String,String> result = accessor.getProperties(""); assertNotNull(result); - assertEquals(result.get("testGetProperties1"), value); + assertEquals(value, result.get("testGetProperties1")); assertNotNull(result.get("_testGetProperties1.createdIndex")); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/f96cbd03/etcd/src/test/java/org/apache/tamaya/etcd/EtcdPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/etcd/src/test/java/org/apache/tamaya/etcd/EtcdPropertySourceTest.java b/etcd/src/test/java/org/apache/tamaya/etcd/EtcdPropertySourceTest.java index 3766c1e..8b6569f 100644 --- a/etcd/src/test/java/org/apache/tamaya/etcd/EtcdPropertySourceTest.java +++ b/etcd/src/test/java/org/apache/tamaya/etcd/EtcdPropertySourceTest.java @@ -41,12 +41,12 @@ public class EtcdPropertySourceTest { @Test public void testGetOrdinal() throws Exception { - assertEquals(propertySource.getOrdinal(), 1000); + assertEquals(1000, propertySource.getOrdinal()); } @Test public void testGetDefaultOrdinal() throws Exception { - assertEquals(propertySource.getDefaultOrdinal(), 1000); + assertEquals(1000, propertySource.getDefaultOrdinal()); } @Test
