/** executes a set of commands by sending them as a single process to `bash -c` * (single command argument of all the commands, joined with separator) * <p> * consequence of this is that you should not normally need to escape things oddly in your commands, * type them just as you would into a bash shell (if you find exceptions please note them here!) */ public static int execProcesses(List<String> cmds, Map<String,?> env, File directory, OutputStream out, OutputStream err, String separator, boolean asLoginShell, Object contextForLogging) { MutableList<String> commands = new MutableList<String>().append("bash"); if (asLoginShell) commands.append("-l"); commands.append("-c", Strings.join(cmds, Preconditions.checkNotNull(separator, "separator"))); return execSingleProcess(commands, env, directory, out, err, contextForLogging); }
.append("which pg_ctl") .appendAll(Iterables.transform(pgctlLocations, StringFunctions.formatter("test -x %s/pg_ctl"))) .append(installPackage(ImmutableMap.of( "yum", "postgresql"+shortVersion+" postgresql"+shortVersion+"-server", "apt", "postgresql-"+majorMinorVersion, ), null)) .append(warn(format("WARNING: failed to find or install postgresql %s binaries", majorMinorVersion))); .append(ifExecutableElse1("pg_ctl", chainGroup( "PG_EXECUTABLE=`which pg_ctl`", "PG_DIR=`dirname $PG_EXECUTABLE`", "ln -s $PG_DIR bin"))) .appendAll(Iterables.transform(pgctlLocations, givenDirIfFileExistsInItLinkToDir("pg_ctl", "bin"))) .append(fail(format("WARNING: failed to find postgresql %s binaries for pg_ctl, may already have another version installed; aborting", majorMinorVersion), 9));
private static void assertVersionOrder(String v1, String v2, String ...otherVersions) { List<String> versions = MutableList.<String>of().append(v1, v2, otherVersions); for (int i=0; i<versions.size(); i++) { for (int j=0; j<versions.size(); j++) { assertEquals(VersionComparator.getInstance().compare( versions.get(i), versions.get(j)), new Integer(i).compareTo(j), "comparing "+versions.get(i)+" and "+versions.get(j)); } } }
c1.append(String.format("%s%s%s", key, keyValueSeparator, Strings.toString(value)));
@Test public void testAddListAddsReference() { MutableList<Object> list = MutableList.<Object>of("a", "b"); Navigator<MutableMap<Object, Object>> j = Jsonya.newInstance().add("root", list); Assert.assertEquals( j.toString(), "{ \"root\": [ \"a\", \"b\" ] }"); list.append("c"); Assert.assertEquals( j.toString(), "{ \"root\": [ \"a\", \"b\", \"c\" ] }"); }
@Test public void testAddListAtRootAddsReference() { MutableList<Object> list = MutableList.<Object>of("a", "b"); Navigator<MutableMap<Object, Object>> j = Jsonya.newInstance().add(list); Assert.assertEquals( j.toString(), "[ \"a\", \"b\" ]"); list.append("c"); Assert.assertEquals( j.toString(), "[ \"a\", \"b\", \"c\" ]"); }
@Test public void testAddListToExistingRootAddsCopy() { MutableList<Object> list = MutableList.<Object>of("a", "b"); Navigator<MutableMap<Object, Object>> j = Jsonya.newInstance().list().add(list); Assert.assertEquals( j.toString(), "[ \"a\", \"b\" ]"); list.append("c"); Assert.assertEquals( j.toString(), "[ \"a\", \"b\" ]"); }
@Test public void testAddListToExistingAddsCopy() { MutableList<Object> list = MutableList.<Object>of("a", "b"); Navigator<MutableMap<Object, Object>> j = Jsonya.newInstance().at("root").list().add(list).root(); Assert.assertEquals( j.toString(), "{ \"root\": [ \"a\", \"b\" ] }"); list.append("c"); Assert.assertEquals( j.toString(), "{ \"root\": [ \"a\", \"b\" ] }"); }
@Test public void testJoinerDefault() { entity.enrichers().add(Enrichers.builder() .joining(LIST_SENSOR) .publishing(TestEntity.NAME) .build()); // null values ignored, and it quotes entity.sensors().set(LIST_SENSOR, MutableList.<String>of("a", "\"b").append(null)); EntityAsserts.assertAttributeEqualsEventually(entity, TestEntity.NAME, "\"a\",\"\\\"b\""); // empty list causes "" entity.sensors().set(LIST_SENSOR, MutableList.<String>of().append(null)); EntityAsserts.assertAttributeEqualsEventually(entity, TestEntity.NAME, ""); // null causes null entity.sensors().set(LIST_SENSOR, null); EntityAsserts.assertAttributeEqualsEventually(entity, TestEntity.NAME, null); }
@Test public void testJoinerUnquoted() { entity.sensors().set(LIST_SENSOR, MutableList.<String>of("a", "\"b", "ccc").append(null)); entity.enrichers().add(Enrichers.builder() .joining(LIST_SENSOR) .publishing(TestEntity.NAME) .minimum(1) .maximum(2) .separator(":") .quote(false) .build()); // in this case, it should be immediately available upon adding the enricher EntityAsserts.assertAttributeEquals(entity, TestEntity.NAME, "a:\"b"); // empty list causes null here, because below the minimum entity.sensors().set(LIST_SENSOR, MutableList.<String>of().append(null)); EntityAsserts.assertAttributeEqualsEventually(entity, TestEntity.NAME, null); }