Improve test location rebind stub

* Makes the stubbed location more functional by implementing the 
getNodeMetadata, setting the location field on the NodeMetadata;
* Disabled aws hostname lookup - nothing to ssh into;
* Sets the HA manager for the new rebind management context to disabled. This 
fixes it to return MASTER state. That's what the launcher does when no HA 
configured.


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/7ce6f0d1
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/7ce6f0d1
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/7ce6f0d1

Branch: refs/heads/master
Commit: 7ce6f0d1fd229f6c31e99a89c98eb8c9f0f9fd73
Parents: 9d3780a
Author: Svetoslav Neykov <svetoslav.ney...@cloudsoftcorp.com>
Authored: Wed Mar 22 18:28:51 2017 +0200
Committer: Svetoslav Neykov <svetoslav.ney...@cloudsoftcorp.com>
Committed: Wed Mar 22 21:55:19 2017 +0200

----------------------------------------------------------------------
 .../brooklyn/AbstractJcloudsStubYamlTest.java   |  1 +
 .../core/mgmt/rebind/RebindTestUtils.java       |  1 +
 .../jclouds/AbstractJcloudsStubbedUnitTest.java |  1 +
 .../jclouds/JcloudsRebindStubUnitTest.java      |  5 +++-
 .../jclouds/StubbedComputeServiceRegistry.java  | 26 ++++++++++++++++++++
 5 files changed, 33 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7ce6f0d1/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractJcloudsStubYamlTest.java
----------------------------------------------------------------------
diff --git 
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractJcloudsStubYamlTest.java
 
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractJcloudsStubYamlTest.java
index fb3255f..380c132 100644
--- 
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractJcloudsStubYamlTest.java
+++ 
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractJcloudsStubYamlTest.java
@@ -115,6 +115,7 @@ public abstract class AbstractJcloudsStubYamlTest extends 
AbstractJcloudsStubbed
                 "    brooklyn.config:",
                 "      identity: myidentity",
                 "      credential: mycredential",
+                "      lookupAwsHostname: false",
                 "      jclouds.computeServiceRegistry:",
                 "        $brooklyn:object:",
                 "          type: " + 
ByonComputeServiceStaticRef.class.getName(),

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7ce6f0d1/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java 
b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
index f274ad5..fa59b5a 100644
--- 
a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
+++ 
b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
@@ -238,6 +238,7 @@ public class RebindTestUtils {
                     classLoader);
             ((RebindManagerImpl) 
unstarted.getRebindManager()).setPeriodicPersistPeriod(persistPeriod);
             unstarted.getRebindManager().setPersister(newPersister, 
PersistenceExceptionHandlerImpl.builder().build());
+            unstarted.getHighAvailabilityManager().disabled();
             // set the HA persister, in case any children want to use HA
             unstarted.getHighAvailabilityManager().setPersister(new 
ManagementPlaneSyncRecordPersisterToObjectStore(unstarted, objectStore, 
classLoader));
             return unstarted;

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7ce6f0d1/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsStubbedUnitTest.java
----------------------------------------------------------------------
diff --git 
a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsStubbedUnitTest.java
 
b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsStubbedUnitTest.java
index 0eef3a6..37231be 100644
--- 
a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsStubbedUnitTest.java
+++ 
b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsStubbedUnitTest.java
@@ -100,6 +100,7 @@ public abstract class AbstractJcloudsStubbedUnitTest 
extends AbstractJcloudsLive
                 .put(SshMachineLocation.SSH_TOOL_CLASS, 
RecordingSshTool.class.getName())
                 .put(WinRmMachineLocation.WINRM_TOOL_CLASS, 
RecordingWinRmTool.class.getName())
                 
.put(JcloudsLocation.POLL_FOR_FIRST_REACHABLE_ADDRESS_PREDICATE, 
Predicates.alwaysTrue())
+                .put(JcloudsLocationConfig.LOOKUP_AWS_HOSTNAME, Boolean.FALSE)
                 .build();
         final ImmutableMap.Builder<Object, Object> flags = 
ImmutableMap.builder()
                 .putAll(jcloudsLocationConfig);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7ce6f0d1/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsRebindStubUnitTest.java
----------------------------------------------------------------------
diff --git 
a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsRebindStubUnitTest.java
 
b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsRebindStubUnitTest.java
index 8a316d3..01cb558 100644
--- 
a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsRebindStubUnitTest.java
+++ 
b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsRebindStubUnitTest.java
@@ -20,6 +20,7 @@ package org.apache.brooklyn.location.jclouds;
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
 
 import java.util.List;
 import java.util.Map;
@@ -169,7 +170,8 @@ public class JcloudsRebindStubUnitTest extends 
RebindTestFixtureWithApp {
         
         assertEquals(newHostname, origHostname);
         assertEquals(origNode.getId(), newNodeId);
-        assertFalse(newNode.isPresent(), "newNode="+newNode);
+        assertTrue(newNode.isPresent(), "newNode="+newNode);
+        assertEquals(newNode.get(), origNode);
         assertFalse(newTemplate.isPresent(), "newTemplate="+newTemplate);
         
         assertEquals(newJcloudsLoc.getProvider(), 
origJcloudsLoc.getProvider());
@@ -194,6 +196,7 @@ public class JcloudsRebindStubUnitTest extends 
RebindTestFixtureWithApp {
                         .put(SshMachineLocation.SSH_TOOL_CLASS, 
RecordingSshTool.class.getName())
                         .put(WinRmMachineLocation.WINRM_TOOL_CLASS, 
RecordingWinRmTool.class.getName())
                         
.put(JcloudsLocation.POLL_FOR_FIRST_REACHABLE_ADDRESS_PREDICATE, 
Predicates.alwaysTrue())
+                        .put(JcloudsLocationConfig.LOOKUP_AWS_HOSTNAME, 
Boolean.FALSE)
                         .putAll(jcloudsLocationConfig)
                         .build());
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7ce6f0d1/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/StubbedComputeServiceRegistry.java
----------------------------------------------------------------------
diff --git 
a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/StubbedComputeServiceRegistry.java
 
b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/StubbedComputeServiceRegistry.java
index b6e7932..e8570ea 100644
--- 
a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/StubbedComputeServiceRegistry.java
+++ 
b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/StubbedComputeServiceRegistry.java
@@ -30,6 +30,8 @@ import org.jclouds.compute.domain.NodeMetadata.Status;
 import org.jclouds.compute.domain.NodeMetadataBuilder;
 import org.jclouds.compute.domain.Template;
 import org.jclouds.compute.options.TemplateOptions;
+import org.jclouds.domain.LocationBuilder;
+import org.jclouds.domain.LocationScope;
 import org.jclouds.domain.LoginCredentials;
 
 import com.google.common.base.Predicate;
@@ -44,6 +46,7 @@ public class StubbedComputeServiceRegistry implements 
ComputeServiceRegistry {
         public Set<? extends NodeMetadata> createNodesInGroup(String group, 
int count, Template template) throws RunNodesException;
         public void destroyNode(String id);
         public Set<? extends NodeMetadata> 
listNodesDetailsMatching(Predicate<? super NodeMetadata> filter);
+        public NodeMetadata getCreatedNode(String nodeId);
     }
 
     public static abstract class AbstractNodeCreator implements NodeCreator {
@@ -69,6 +72,14 @@ public class StubbedComputeServiceRegistry implements 
ComputeServiceRegistry {
             return ImmutableSet.of();
         }
         protected abstract NodeMetadata newNode(String group, Template 
template);
+        public NodeMetadata getCreatedNode(String nodeId) {
+            for (NodeMetadata node : created) {
+                if (node.getId().equals(nodeId)) {
+                    return node;
+                }
+            }
+            return null;
+        }
     }
 
     public static class SingleNodeCreator extends AbstractNodeCreator {
@@ -88,6 +99,16 @@ public class StubbedComputeServiceRegistry implements 
ComputeServiceRegistry {
         @Override
         protected NodeMetadata newNode(String group, Template template) {
             int suffix = counter.getAndIncrement();
+            org.jclouds.domain.Location region = new LocationBuilder()
+                    .scope(LocationScope.REGION)
+                    .id("us-east-1")
+                    .description("us-east-1")
+                    .parent(new LocationBuilder()
+                            .scope(LocationScope.PROVIDER)
+                            .id("aws-ec2")
+                            .description("aws-ec2")
+                            .build())
+                    .build();
             NodeMetadata result = new NodeMetadataBuilder()
                     .id("mynodeid"+suffix)
                     
.credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build())
@@ -95,6 +116,7 @@ public class StubbedComputeServiceRegistry implements 
ComputeServiceRegistry {
                     .status(Status.RUNNING)
                     .publicAddresses(ImmutableList.of("173.194.32."+suffix))
                     .privateAddresses(ImmutableList.of("172.168.10."+suffix))
+                    .location(region)
                     .build();
             return result;
         }
@@ -159,6 +181,10 @@ public class StubbedComputeServiceRegistry implements 
ComputeServiceRegistry {
         public Set<? extends NodeMetadata> createNodesInGroup(String group, 
int count, TemplateOptions templateOptions) {
             throw new UnsupportedOperationException();
         }
+        @Override
+        public NodeMetadata getNodeMetadata(String id) {
+            return nodeCreator.getCreatedNode(id);
+        }
     }
     
     private final NodeCreator nodeCreator;

Reply via email to