@Override public Collection<BrooklynObject> get() { return MutableSet.of(); } });
private static boolean firstEncounter(Throwable t) { Set<Object> record = MutableSet.of(); while (true) { record.add(t.getClass()); if (t.getStackTrace().length>0) { if (record.add(t.getStackTrace()[0])) break; } t = t.getCause(); if (t==null) break; } return encounteredExceptionRecords.add(record); }
private static Set<ConfigKey<?>> filterOutRuntimeNotReinherited(Set<ConfigKey<?>> inherited) { Set<ConfigKey<?>> result = MutableSet.of(); for (ConfigKey<?> k: inherited) { if (ConfigInheritances.isKeyReinheritable(k, InheritanceContext.RUNTIME_MANAGEMENT)) { result.add(k); } } return result; }
/** @return the ports required for a specific child entity */ protected Collection<Integer> getRequiredOpenPorts(Entity entity) { Set<Integer> ports = MutableSet.of(); addRequiredOpenPortsRecursively(entity, ports); return ports; }
/** Returns the set of configured ports an entity is listening on. */ public static Set<Integer> getOpenPorts(Entity entity) { Set<Integer> ports = MutableSet.of(22); // Default for SSH, may be removed ports.addAll(getMappedPorts(entity).keySet()); return ImmutableSet.copyOf(ports); }
public static Set<Location> getAllInheritedLocations(Entity entity) { Set<Location> result = MutableSet.of(); while (entity!=null) { result.addAll(entity.getLocations()); entity = entity.getParent(); } return result; }
public static <V> MutableSet<V> copyOf(@Nullable Iterator<? extends V> elements) { if (elements == null || !elements.hasNext()) { return of(); } return new MutableSet.Builder<V>().addAll(elements).build(); }
public void testEqualsDifferentTypes2() { Set<Object> a = MutableSet.<Object>of("http"); Set<?> b = ImmutableSet.of("http"); Assert.assertEquals(a, b); Assert.assertEquals(b, a); }
@Test public void testMutableSet() throws Exception { Set<?> obj = MutableSet.of("123"); assertSerializeAndDeserialize(obj); }
@Test public void testIterableToArrayCoercion() { String[] s = coerce(ImmutableList.of("a", "b"), String[].class); Assert.assertTrue(Arrays.equals(s, new String[] {"a", "b"}), "result="+Arrays.toString(s)); Integer[] i = coerce(ImmutableList.of(1, 2), Integer[].class); Assert.assertTrue(Arrays.equals(i, new Integer[] {1, 2}), "result="+Arrays.toString(i)); int[] i2 = coerce(ImmutableList.of(1, 2), int[].class); Assert.assertTrue(Arrays.equals(i2, new int[] {1, 2}), "result="+Arrays.toString(i2)); int[] i3 = coerce(MutableSet.of("1", 2), int[].class); Assert.assertTrue(Arrays.equals(i3, new int[] {1, 2}), "result="+Arrays.toString(i3)); }
@Test public void test12CollapsePropagatedExecutionCompoundBoring() throws Exception { RuntimeException e = new PropagatedRuntimeException("test1", new ExecutionException(Exceptions.create(MutableSet.of(new IllegalStateException("test2"), new IllegalStateException("test3"))))); assert12StandardChecks(e, true); }
@Test public void testCanStartSameNode() throws Exception { // not very interesting as do not have REST when run in this project // but test BrooklynNodeRestTest in downstream project does BrooklynNode bn = app.createAndManageChild(EntitySpec.create(BrooklynNode.class, SameBrooklynNodeImpl.class)); bn.start(MutableSet.<Location>of()); Assert.assertEquals(bn.getAttribute(Attributes.SERVICE_UP), (Boolean) true); // no URI Assert.assertNull(bn.getAttribute(BrooklynNode.WEB_CONSOLE_URI)); }
@Test public void testPassesJavaOptsOverridingDefaults() { VanillaJavaApp javaProcess = app.createAndManageChild(EntitySpec.create(VanillaJavaApp.class) .configure("main", "my.Main").configure("useJmx", false).configure("javaOpts", ImmutableList.of("-Xmx567m", "-XX:MaxPermSize=567m"))); app.start(ImmutableList.of(loc)); String runDir = javaProcess.getRunDir(); Object expectedJavaOpts = MutableSet.of("-Xms128m", "-Xmx567m", "-XX:MaxPermSize=567m"); Map<String,Object> expectedEnvs = ImmutableMap.<String,Object>of("JAVA_OPTS", expectedJavaOpts); List<String> expectedCmds = ImmutableList.of(String.format("java $JAVA_OPTS -cp \"%1$s/lib\" my.Main >> %1$s/console 2>&1 </dev/null &", runDir)); assertHasExpectedCmds(expectedCmds, expectedEnvs); }
@Test public void testJsonyaMaybe() { Navigator<MutableMap<Object, Object>> m = europeMap(); Assert.assertEquals( m.at("europe", "spain", "barcelona").getMaybe().or("norealabc"), "norealabc" ); Assert.assertEquals(m.root().at("europe").getFocusMap().keySet(), MutableSet.of("uk", "france")); }
@Test public void testTagsFromSpec() throws Exception { MyEnricher enricher = app.enrichers().add(EnricherSpec.create(MyEnricher.class).tag(99).uniqueTag("x")); assertEquals(enricher.tags().getTags(), MutableSet.of("x", 99)); assertEquals(enricher.getUniqueTag(), "x"); }
@Test public void testTagsFromSpec() throws Exception { MyPolicy policy = app.policies().add(PolicySpec.create(MyPolicy.class).tag(99).uniqueTag("x")); assertEquals(policy.tags().getTags(), MutableSet.of("x", 99)); assertEquals(policy.getUniqueTag(), "x"); }
@SuppressWarnings({ "unchecked", "rawtypes" }) public void testSetEmpty() throws Exception { // ensure it is null before we pass something in, and passing an empty collection makes it be empty log.info("Set-Empty-1: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig())); Assert.assertEquals(entity.getConfig(TestEntity.CONF_SET_THING), null); entity.config().set((SetConfigKey)TestEntity.CONF_SET_THING, MutableSet.of()); log.info("Set-Empty-2: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig())); Assert.assertEquals(entity.getConfig(TestEntity.CONF_SET_THING), ImmutableSet.of()); }
@Test public void testSelectionWithOrphanedLocationsInData() throws Exception { final Set<String> orphanedLocations = MutableSet.of( "msyp655po0", "ppamsemxgo" ); initManagementContextAndPersistence(persistenceDirWithOrphanedLocations); BrooklynMementoRawData mementoRawData = mgmt.getRebindManager().retrieveMementoRawData(); assertTransformDeletes(new Deletions().locations(orphanedLocations), mementoRawData); }
public void testCustomEntityRelation() { TestEntity t1 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); TestEntity t2 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); t1.relations().add(EntityRelations.HAS_TARGET, t2); Assert.assertEquals(t1.relations().getRelations(EntityRelations.HAS_TARGET), Collections.singleton(t2)); Assert.assertEquals(t2.relations().getRelations(EntityRelations.HAS_TARGET), Collections.emptySet()); Assert.assertEquals(t2.relations().getRelations(EntityRelations.TARGETTED_BY), Collections.singleton(t1)); t1.relations().add(EntityRelations.HAS_TARGET, t2); Assert.assertEquals(t1.relations().getRelations(EntityRelations.HAS_TARGET), Collections.singleton(t2)); t1.relations().add(EntityRelations.HAS_TARGET, t1); Assert.assertEquals(t1.relations().getRelations(EntityRelations.HAS_TARGET), MutableSet.of(t1, t2)); }