You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by po...@apache.org on 2017/11/12 23:02:04 UTC
incubator-tamaya-sandbox git commit: TAMAYA-218: Rework consul tests
Repository: incubator-tamaya-sandbox
Updated Branches:
refs/heads/master c706c55d7 -> 31585cdc0
TAMAYA-218: Rework consul tests
Make it more explicit that tests are not integration tests
without a manually deployed Consul and do not run at all.
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/31585cdc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/31585cdc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/31585cdc
Branch: refs/heads/master
Commit: 31585cdc0677c60a1afc22c8e46ebf686f58f5f5
Parents: c706c55
Author: Phil Ottlinger <po...@apache.org>
Authored: Mon Nov 13 00:01:15 2017 +0100
Committer: Phil Ottlinger <po...@apache.org>
Committed: Mon Nov 13 00:01:15 2017 +0100
----------------------------------------------------------------------
.../tamaya/consul/ConsulBackendConfig.java | 12 ++++----
.../tamaya/consul/ConsulPropertySource.java | 6 ++--
.../tamaya/consul/ConsulPropertySourceTest.java | 4 +--
.../apache/tamaya/consul/ConsulWriteTest.java | 30 ++++++++++++--------
4 files changed, 30 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/31585cdc/consul/src/main/java/org/apache/tamaya/consul/ConsulBackendConfig.java
----------------------------------------------------------------------
diff --git a/consul/src/main/java/org/apache/tamaya/consul/ConsulBackendConfig.java b/consul/src/main/java/org/apache/tamaya/consul/ConsulBackendConfig.java
index 958a843..61be0ba 100644
--- a/consul/src/main/java/org/apache/tamaya/consul/ConsulBackendConfig.java
+++ b/consul/src/main/java/org/apache/tamaya/consul/ConsulBackendConfig.java
@@ -31,13 +31,15 @@ import java.util.logging.Logger;
*/
public final class ConsulBackendConfig {
- private static final Logger LOG = Logger.getLogger(ConsulBackendConfig.class.getName());
+ private static final String TAMAYA_CONSUL_DISABLE = "tamaya.consul.disable";
+ private static final String TAMAYA_CONSUL_URLS = "tamaya.consul.urls";
+ private static final Logger LOG = Logger.getLogger(ConsulBackendConfig.class.getName());
private static List<HostAndPort> consulBackends = new ArrayList<>();
static{
- String serverURLs = System.getProperty("tamaya.consul.urls");
+ String serverURLs = System.getProperty(TAMAYA_CONSUL_URLS);
if(serverURLs==null){
- serverURLs = System.getenv("tamaya.consul.urls");
+ serverURLs = System.getenv(TAMAYA_CONSUL_URLS);
}
if(serverURLs==null){
serverURLs = "127.0.0.1:8300";
@@ -55,9 +57,9 @@ public final class ConsulBackendConfig {
private ConsulBackendConfig(){}
private static boolean isConsulDisabled() {
- String value = System.getProperty("tamaya.consul.disable");
+ String value = System.getProperty(TAMAYA_CONSUL_DISABLE);
if(value==null){
- value = System.getenv("tamaya.consul.disable");
+ value = System.getenv(TAMAYA_CONSUL_DISABLE);
}
if(value==null){
return false;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/31585cdc/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
----------------------------------------------------------------------
diff --git a/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java b/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
index c99eca4..30a1de7 100644
--- a/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
+++ b/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
@@ -35,7 +35,7 @@ import java.util.logging.Logger;
/**
* Propertysource that is reading configuration from a configured consul endpoint. Setting
- * {@code consul.prefix} as system property maps the consul based onfiguration
+ * {@code consul.prefix} as system property maps the consul based configuration
* to this prefix namespace. Consul servers are configured as {@code consul.urls} system or environment property.
*/
public class ConsulPropertySource extends BasePropertySource
@@ -140,7 +140,7 @@ implements MutablePropertySource{
if(!valueOpt.isPresent()) {
LOG.log(Level.FINE, "key not found in consul: " + reqKey);
}else{
- // No repfix mapping necessary here, since we only access/return the value...
+ // No prefix mapping necessary here, since we only access/return the value...
Value value = valueOpt.get();
Map<String,String> props = new HashMap<>();
props.put(reqKey+".createIndex", String.valueOf(value.getCreateIndex()));
@@ -174,7 +174,7 @@ implements MutablePropertySource{
// LOG.log(Level.FINE, "consul access failed on " + hostAndPort + ", trying next...", e);
// }
// } catch(Exception e){
-// LOG.log(Level.FINE, "etcd access failed on " + hostAndPort + ", trying next...", e);
+// LOG.log(Level.FINE, "consul access failed on " + hostAndPort + ", trying next...", e);
// }
// }
return Collections.emptyMap();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/31585cdc/consul/src/test/java/org/apache/tamaya/consul/ConsulPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/consul/src/test/java/org/apache/tamaya/consul/ConsulPropertySourceTest.java b/consul/src/test/java/org/apache/tamaya/consul/ConsulPropertySourceTest.java
index a71f577..0366b2b 100644
--- a/consul/src/test/java/org/apache/tamaya/consul/ConsulPropertySourceTest.java
+++ b/consul/src/test/java/org/apache/tamaya/consul/ConsulPropertySourceTest.java
@@ -42,12 +42,12 @@ public class ConsulPropertySourceTest {
@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
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/31585cdc/consul/src/test/java/org/apache/tamaya/consul/ConsulWriteTest.java
----------------------------------------------------------------------
diff --git a/consul/src/test/java/org/apache/tamaya/consul/ConsulWriteTest.java b/consul/src/test/java/org/apache/tamaya/consul/ConsulWriteTest.java
index 4b3452d..1746030 100644
--- a/consul/src/test/java/org/apache/tamaya/consul/ConsulWriteTest.java
+++ b/consul/src/test/java/org/apache/tamaya/consul/ConsulWriteTest.java
@@ -18,35 +18,41 @@
*/
package org.apache.tamaya.consul;
-import com.google.common.net.HostAndPort;
-import org.apache.tamaya.mutableconfig.ConfigChangeRequest;
-import org.apache.tamaya.spi.PropertyValue;
-import org.junit.BeforeClass;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.Map;
import java.util.UUID;
-import static org.junit.Assert.*;
+import org.apache.tamaya.mutableconfig.ConfigChangeRequest;
+import org.apache.tamaya.spi.PropertyValue;
+import org.junit.BeforeClass;
+import org.junit.Test;
/**
- * Tests for th consul backend integration for writing to the consul backend.
+ * Tests for the consul backend integration for writing to the consul backend.
*/
public class ConsulWriteTest {
- private static HostAndPort accessor;
+ /**
+ * Needs to be enabled manually in case you want to do integration tests.
+ */
static boolean execute = false;
private static ConsulPropertySource propertySource;
@BeforeClass
public static void setup() throws MalformedURLException, URISyntaxException {
System.setProperty("consul.urls", "http://127.0.0.1:8300");
- accessor = HostAndPort.fromString("127.0.0.1:8500");
propertySource = new ConsulPropertySource();
+
+ System.out.println("At the moment no write-tests can be executed to verify the Consul integration. You can manually edit this test class.");
}
- @org.junit.Test
+ @Test
public void testSetNormal() throws Exception {
if (!execute) return;
String taID = UUID.randomUUID().toString();
@@ -56,14 +62,14 @@ public class ConsulWriteTest {
}
- @org.junit.Test
+ @Test
public void testDelete() throws Exception {
if(!execute)return;
String taID = UUID.randomUUID().toString();
ConfigChangeRequest request = new ConfigChangeRequest("testDelete");
request.put(taID, "testDelete");
propertySource.applyChange(request);
- assertEquals(propertySource.get("testDelete").getValue(), taID.toString());
+ assertEquals(taID.toString(), propertySource.get("testDelete").getValue());
assertNotNull(propertySource.get("_testDelete.createdIndex"));
request = new ConfigChangeRequest("testDelete2");
request.remove("testDelete");
@@ -71,7 +77,7 @@ public class ConsulWriteTest {
assertNull(propertySource.get("testDelete"));
}
- @org.junit.Test
+ @Test
public void testGetProperties() throws Exception {
if(!execute)return;
Map<String,PropertyValue> result = propertySource.getProperties();