JCLOUDS-428: Use Maps with a consistent iteration order

This commit is contained in:
Ignasi Barrera 2014-08-26 10:32:04 +02:00 committed by Jeremy Daggett
parent 00ae5a4763
commit d82e9705d7
7 changed files with 22 additions and 26 deletions

View File

@ -155,7 +155,7 @@ public class BaseChefService implements ChefService {
String buildBootstrapConfiguration(BootstrapConfig bootstrapConfig) { String buildBootstrapConfiguration(BootstrapConfig bootstrapConfig) {
checkNotNull(bootstrapConfig, "bootstrapConfig must not be null"); checkNotNull(bootstrapConfig, "bootstrapConfig must not be null");
Map<String, Object> configMap = Maps.newHashMap(); Map<String, Object> configMap = Maps.newLinkedHashMap();
configMap.put("run_list", bootstrapConfig.getRunList()); configMap.put("run_list", bootstrapConfig.getRunList());
if (bootstrapConfig.getEnvironment().isPresent()) { if (bootstrapConfig.getEnvironment().isPresent()) {

View File

@ -94,7 +94,7 @@ public class NestSlashKeys implements Function<Multimap<String, Supplier<JsonBal
@VisibleForTesting @VisibleForTesting
void mergeAsPeer(String key, JsonBall value, Map<String, JsonBall> insertionContext) { void mergeAsPeer(String key, JsonBall value, Map<String, JsonBall> insertionContext) {
Map<String, JsonBall> immutableValueContext = json.fromJson(insertionContext.get(key).toString(), mapLiteral); Map<String, JsonBall> immutableValueContext = json.fromJson(insertionContext.get(key).toString(), mapLiteral);
Map<String, JsonBall> valueContext = Maps.newHashMap(immutableValueContext); Map<String, JsonBall> valueContext = Maps.newLinkedHashMap(immutableValueContext);
Map<String, JsonBall> toPut = json.<Map<String, JsonBall>> fromJson(value.toString(), mapLiteral); Map<String, JsonBall> toPut = json.<Map<String, JsonBall>> fromJson(value.toString(), mapLiteral);
Set<String> uniques = Sets.difference(toPut.keySet(), valueContext.keySet()); Set<String> uniques = Sets.difference(toPut.keySet(), valueContext.keySet());
for (String k : uniques) { for (String k : uniques) {
@ -135,7 +135,7 @@ public class NestSlashKeys implements Function<Multimap<String, Supplier<JsonBal
checkArgument(rootValue.matches("^\\{.*\\}$"), "value must be a hash: %s", rootValue); checkArgument(rootValue.matches("^\\{.*\\}$"), "value must be a hash: %s", rootValue);
Map<String, JsonBall> immutableInsertionContext = json.fromJson(rootValue, mapLiteral); Map<String, JsonBall> immutableInsertionContext = json.fromJson(rootValue, mapLiteral);
Map<String, JsonBall> insertionContext = Maps.newHashMap(immutableInsertionContext); Map<String, JsonBall> insertionContext = Maps.newLinkedHashMap(immutableInsertionContext);
if (keyParts.size() == 1) { if (keyParts.size() == 1) {
if (!insertionContext.containsKey(keyParts.get(0))) { if (!insertionContext.containsKey(keyParts.get(0))) {
insertionContext.put(keyParts.get(0), toInsert); insertionContext.put(keyParts.get(0), toInsert);

View File

@ -84,7 +84,7 @@ public class BaseChefServiceTest {
BootstrapConfig bootstrapConfig = BootstrapConfig.builder().runList(runlist) BootstrapConfig bootstrapConfig = BootstrapConfig.builder().runList(runlist)
.attributes(new JsonBall("{\"tomcat6\":{\"ssl_port\":8433}}")).build(); .attributes(new JsonBall("{\"tomcat6\":{\"ssl_port\":8433}}")).build();
String config = chefService.buildBootstrapConfiguration(bootstrapConfig); String config = chefService.buildBootstrapConfiguration(bootstrapConfig);
assertEquals(config, "{\"tomcat6\":{\"ssl_port\":8433},\"run_list\":[\"recipe[apache2]\",\"role[webserver]\"]}"); assertEquals(config, "{\"run_list\":[\"recipe[apache2]\",\"role[webserver]\"],\"tomcat6\":{\"ssl_port\":8433}}");
} }
public void testBuildBootstrapConfigurationWithRunlistAndAttributesAndEnvironment() { public void testBuildBootstrapConfigurationWithRunlistAndAttributesAndEnvironment() {
@ -93,7 +93,7 @@ public class BaseChefServiceTest {
.attributes(new JsonBall("{\"tomcat6\":{\"ssl_port\":8433}}")).environment("env").build(); .attributes(new JsonBall("{\"tomcat6\":{\"ssl_port\":8433}}")).environment("env").build();
String config = chefService.buildBootstrapConfiguration(bootstrapConfig); String config = chefService.buildBootstrapConfiguration(bootstrapConfig);
assertEquals(config, assertEquals(config,
"{\"tomcat6\":{\"ssl_port\":8433},\"environment\":\"env\",\"run_list\":[\"recipe[apache2]\",\"role[webserver]\"]}"); "{\"run_list\":[\"recipe[apache2]\",\"role[webserver]\"],\"environment\":\"env\",\"tomcat6\":{\"ssl_port\":8433}}");
} }
} }

View File

@ -133,7 +133,7 @@ public class OhaiModuleTest {
assertEquals( assertEquals(
json.toJson(ohai.ohai.get(), new TypeLiteral<Map<String, JsonBall>>() { json.toJson(ohai.ohai.get(), new TypeLiteral<Map<String, JsonBall>>() {
}.getType()), }.getType()),
"{\"ohai_time\":1279992919,\"platform\":\"macosx\",\"platform_version\":\"10.3.0\",\"current_user\":\"user\",\"test\":{\"prop2\":\"test2\",\"prop1\":\"test1\"},\"jvm\":{\"system\":{\"user.name\":\"user\",\"os.version\":\"10.3.0\",\"os.name\":\"Mac OS X\"}}}"); "{\"ohai_time\":1279992919,\"platform\":\"macosx\",\"platform_version\":\"10.3.0\",\"current_user\":\"user\",\"test\":{\"prop1\":\"test1\",\"prop2\":\"test2\"},\"jvm\":{\"system\":{\"user.name\":\"user\",\"os.version\":\"10.3.0\",\"os.name\":\"Mac OS X\"}}}");
} }
static class Ohai { static class Ohai {

View File

@ -31,7 +31,7 @@ import org.testng.annotations.Test;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers; import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableListMultimap;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -39,7 +39,7 @@ import com.google.inject.Injector;
/** /**
* Tests behavior of {@code NestSlashKeys} * Tests behavior of {@code NestSlashKeys}
*/ */
@Test(groups = { "unit" }, sequential = true) @Test(groups = "unit", testName = "NestSlashKeysTest")
public class NestSlashKeysTest { public class NestSlashKeysTest {
private NestSlashKeys converter; private NestSlashKeys converter;
@ -60,56 +60,56 @@ public class NestSlashKeysTest {
@Test @Test
public void testBase() { public void testBase() {
assertEquals( assertEquals(
json.toJson(converter.apply(ImmutableMultimap.<String, Supplier<JsonBall>> of("java", json.toJson(converter.apply(ImmutableListMultimap.<String, Supplier<JsonBall>> of("java",
Suppliers.ofInstance(new JsonBall("java"))))), "{\"java\":\"java\"}"); Suppliers.ofInstance(new JsonBall("java"))))), "{\"java\":\"java\"}");
} }
@Test(expectedExceptions = IllegalArgumentException.class) @Test(expectedExceptions = IllegalArgumentException.class)
public void testIllegal() { public void testIllegal() {
json.toJson(converter.apply(ImmutableMultimap.<String, Supplier<JsonBall>> of("java", json.toJson(converter.apply(ImmutableListMultimap.<String, Supplier<JsonBall>> of("java",
Suppliers.ofInstance(new JsonBall("java")), "java/system", Suppliers.ofInstance(new JsonBall("system"))))); Suppliers.ofInstance(new JsonBall("java")), "java/system", Suppliers.ofInstance(new JsonBall("system")))));
} }
@Test @Test
public void testOne() { public void testOne() {
assertEquals( assertEquals(
json.toJson(converter.apply(ImmutableMultimap.<String, Supplier<JsonBall>> of("java", json.toJson(converter.apply(ImmutableListMultimap.<String, Supplier<JsonBall>> of("java",
Suppliers.ofInstance(new JsonBall("{\"time\":\"time\"}")), "java/system", Suppliers.ofInstance(new JsonBall("{\"time\":\"time\"}")), "java/system",
Suppliers.ofInstance(new JsonBall("system"))))), Suppliers.ofInstance(new JsonBall("system"))))),
"{\"java\":{\"system\":\"system\",\"time\":\"time\"}}"); "{\"java\":{\"time\":\"time\",\"system\":\"system\"}}");
} }
@Test @Test
public void testOneDuplicate() { public void testOneDuplicate() {
assertEquals( assertEquals(
json.toJson(converter.apply(ImmutableMultimap.<String, Supplier<JsonBall>> of("java", json.toJson(converter.apply(ImmutableListMultimap.<String, Supplier<JsonBall>> of("java",
Suppliers.ofInstance(new JsonBall("{\"time\":\"time\"}")), "java", Suppliers.ofInstance(new JsonBall("{\"time\":\"time\"}")), "java",
Suppliers.ofInstance(new JsonBall("{\"system\":\"system\"}"))))), Suppliers.ofInstance(new JsonBall("{\"system\":\"system\"}"))))),
"{\"java\":{\"system\":\"system\",\"time\":\"time\"}}"); "{\"java\":{\"time\":\"time\",\"system\":\"system\"}}");
} }
@Test @Test
public void testMerge() { public void testMerge() {
assertEquals( assertEquals(
json.toJson(converter.apply(ImmutableMultimap.<String, Supplier<JsonBall>> of("java", json.toJson(converter.apply(ImmutableListMultimap.<String, Supplier<JsonBall>> of("java",
Suppliers.ofInstance(new JsonBall("{\"time\":{\"1\":\"hello\"}}")), "java/time", Suppliers.ofInstance(new JsonBall("{\"time\":{\"1\":\"hello\"}}")), "java/time",
Suppliers.ofInstance(new JsonBall("{\"2\":\"goodbye\"}"))))), Suppliers.ofInstance(new JsonBall("{\"2\":\"goodbye\"}"))))),
"{\"java\":{\"time\":{\"2\":\"goodbye\",\"1\":\"hello\"}}}"); "{\"java\":{\"time\":{\"1\":\"hello\",\"2\":\"goodbye\"}}}");
} }
@Test @Test
public void testMergeNestedTwice() { public void testMergeNestedTwice() {
assertEquals( assertEquals(
json.toJson(converter.apply(ImmutableMultimap.<String, Supplier<JsonBall>> of("java", json.toJson(converter.apply(ImmutableListMultimap.<String, Supplier<JsonBall>> of("java",
Suppliers.ofInstance(new JsonBall("{\"time\":{\"1\":\"hello\"}}")), "java", Suppliers.ofInstance(new JsonBall("{\"time\":{\"1\":\"hello\"}}")), "java",
Suppliers.ofInstance(new JsonBall("{\"time\":{\"2\":\"goodbye\"}}"))))), Suppliers.ofInstance(new JsonBall("{\"time\":{\"2\":\"goodbye\"}}"))))),
"{\"java\":{\"time\":{\"2\":\"goodbye\",\"1\":\"hello\"}}}"); "{\"java\":{\"time\":{\"1\":\"hello\",\"2\":\"goodbye\"}}}");
} }
@Test @Test
public void testReplaceList() { public void testReplaceList() {
assertEquals( assertEquals(
json.toJson(converter.apply(ImmutableMultimap.<String, Supplier<JsonBall>> of("java", json.toJson(converter.apply(ImmutableListMultimap.<String, Supplier<JsonBall>> of("java",
Suppliers.ofInstance(new JsonBall("{\"time\":{\"1\":[\"hello\"]}}")), "java/time", Suppliers.ofInstance(new JsonBall("{\"time\":{\"1\":[\"hello\"]}}")), "java/time",
Suppliers.ofInstance(new JsonBall("{\"1\":[\"goodbye\"]}"))))), Suppliers.ofInstance(new JsonBall("{\"1\":[\"goodbye\"]}"))))),
"{\"java\":{\"time\":{\"1\":[\"goodbye\"]}}}"); "{\"java\":{\"time\":{\"1\":[\"goodbye\"]}}}");

View File

@ -24,7 +24,6 @@ import java.util.Map;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;

View File

@ -19,12 +19,9 @@ package org.jclouds.openstack.cinder.v1;
import java.io.Closeable; import java.io.Closeable;
import java.util.Set; import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Zone; import org.jclouds.location.Zone;
import org.jclouds.location.functions.ZoneToEndpoint; import org.jclouds.location.functions.ZoneToEndpoint;
import org.jclouds.openstack.cinder.v1.domain.Snapshot;
import org.jclouds.openstack.cinder.v1.domain.Volume;
import org.jclouds.openstack.cinder.v1.domain.VolumeType;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.openstack.cinder.v1.extensions.AvailabilityZoneApi; import org.jclouds.openstack.cinder.v1.extensions.AvailabilityZoneApi;
import org.jclouds.openstack.cinder.v1.features.QuotaApi; import org.jclouds.openstack.cinder.v1.features.QuotaApi;
import org.jclouds.openstack.cinder.v1.features.SnapshotApi; import org.jclouds.openstack.cinder.v1.features.SnapshotApi;
@ -55,7 +52,7 @@ public interface CinderApi extends Closeable {
@Provides @Provides
@Zone @Zone
Set<String> getConfiguredZones(); Set<String> getConfiguredZones();
/** /**
* Provides synchronous access to Extension features. * Provides synchronous access to Extension features.
*/ */
@ -76,7 +73,7 @@ public interface CinderApi extends Closeable {
@Delegate @Delegate
VolumeTypeApi getVolumeTypeApiForZone( VolumeTypeApi getVolumeTypeApiForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); @EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/** /**
* Provides synchronous access to Snapshot features. * Provides synchronous access to Snapshot features.
*/ */