private Set<?> mergeSetsImpl(Set<?> val1, Set<?> val2, int depthRemaining, Visited visited) { return MutableSet.builder() .addAll(val1) .addAll(val2) .build(); }
Set<String> result = MutableSet.<String> builder(). addAll(getJmxJavaConfigOptions()). addAll(getCustomJavaConfigOptions()).
@SuppressWarnings("unchecked") protected <T extends Entity> T createEntityProxy(Iterable<Class<?>> interfaces, T entity) { // We don't especially want the proxy to have to implement EntityLocal, // but required by how AbstractEntity.parent is used (e.g. parent.getAllConfig). // However within EntityProxyImpl we place add'l guards to prevent read-only access to such methods Set<Class<?>> allInterfaces = MutableSet.<Class<?>>builder() .add(EntityProxy.class, Entity.class, EntityLocal.class, EntityInternal.class) .addAll(interfaces) .build(); // TODO OSGi strangeness! The classloader obtained from the type should be enough. // If an OSGi class loader, it should delegate to find things like Entity.class etc. // However, we get errors such as: // NoClassDefFoundError: org.apache.brooklyn.api.sensor.AttributeSensor not found by ....brooklyn-test-osgi-entities // Building our own aggregating class loader gets around this. // But we really should not have to do this! What are the consequences? // // The reason for the error is that the proxy tries to load all classes // referenced from the entity and its interfaces with the single passed loader // while a normal class loading would nest the class loaders (loading interfaces' // references with their own class loaders which in our case are different). AggregateClassLoader aggregateClassLoader = classLoaderCache.getClassLoaderForProxy(entity.getClass(), allInterfaces); return (T) java.lang.reflect.Proxy.newProxyInstance( aggregateClassLoader, allInterfaces.toArray(new Class[allInterfaces.size()]), new EntityProxyImpl(entity)); }
public void testBuilderRetainAll() throws Exception { Set<Object> vals = MutableSet.builder() .add(1,2,3) .retainAll(ImmutableList.of(1,2)) .build(); Assert.assertEquals(vals, ImmutableSet.of(1,2)); }
public void testBuilderAddIterator() throws Exception { Set<Object> vals = MutableSet.builder().addAll(ImmutableSet.of(1,2).iterator()).build(); Assert.assertEquals(vals, ImmutableSet.of(1,2)); }
Set<String> newlyDiscoveredLocs = MutableSet.<String>builder() .addAll(referencedLocs) .removeAll(alreadyReferencedLocations)
public void testBuilderAddArray() throws Exception { Set<Object> vals = MutableSet.builder().addAll(new Object[] {1,2,3}).build(); Assert.assertEquals(vals, ImmutableSet.of(1,2,3)); }
public void testBuilderAddVarargs() throws Exception { Set<Object> vals = MutableSet.builder().add(1,2,3).build(); Assert.assertEquals(vals, ImmutableSet.of(1,2,3)); }
public void testBuilderAddIterable() throws Exception { Set<Object> vals = MutableSet.builder().addAll(ImmutableSet.of(1,2)).addAll(ImmutableSet.of(2,3)).build(); Assert.assertEquals(vals, ImmutableSet.of(1,2,3)); }
public void testBuilderAddIfNotNull() throws Exception { Set<Object> vals = MutableSet.builder().addIfNotNull(1).addIfNotNull(null).build(); Assert.assertEquals(vals, ImmutableSet.of(1)); }
public void testBuilderRemoveAll() throws Exception { Set<Object> vals = MutableSet.builder() .add(1,2,3) .removeAll(ImmutableSet.of(2,3)) .add(4) .build(); Assert.assertEquals(vals, ImmutableSet.of(1,4)); }
public void testBuilderRemoval() throws Exception { Set<Object> vals = MutableSet.builder() .add(1,2,3) .remove(2) .add(4) .build(); Assert.assertEquals(vals, ImmutableSet.of(1,3,4)); }
@Test public void testRemoveConfigKey() throws Exception { entity.getMutableEntityType().removeConfigKey(ConfigEntityForTesting.INSTALL_UNIQUE_LABEL); assertEquals(entity.getEntityType().getConfigKeys(), MutableSet.builder().addAll(DEFAULT_CONFIG_KEYS).remove(ConfigEntityForTesting.INSTALL_UNIQUE_LABEL).build().asUnmodifiable()); assertEventuallyListenerEventsEqual(ImmutableList.of( BasicSensorEvent.ofUnchecked(AbstractEntity.CONFIG_KEY_REMOVED, entity, ConfigEntityForTesting.INSTALL_UNIQUE_LABEL))); }
@Test public void testRemoveSensor() throws Exception { entity.getMutableEntityType().removeSensor(SENSOR_ADDED); assertEquals(entity.getEntityType().getSensors(), MutableSet.builder().addAll(DEFAULT_SENSORS).remove(SENSOR_ADDED).build().asUnmodifiable()); assertEventuallyListenerEventsEqual(ImmutableList.of( BasicSensorEvent.ofUnchecked(SENSOR_REMOVED, entity, SENSOR_ADDED))); }
@Test public void testUpdateCalledWithAddressesOfNewChildren() { // First child cluster.resize(1); Entity child = Iterables.getOnlyElement(cluster.getMembers()); List<Collection<String>> u = Lists.newArrayList(controller.getUpdates()); assertTrue(u.isEmpty(), "expected empty list but got "+u); child.sensors().set(WebServerEntity.HTTP_PORT, 1234); child.sensors().set(Startable.SERVICE_UP, true); assertEventuallyAddressesMatchCluster(); // Second child cluster.resize(2); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertEquals(cluster.getMembers().size(), 2); }}); Entity child2 = Iterables.getOnlyElement(MutableSet.<Entity>builder().addAll(cluster.getMembers()).remove(child).build()); child2.sensors().set(WebServerEntity.HTTP_PORT, 1234); child2.sensors().set(Startable.SERVICE_UP, true); assertEventuallyAddressesMatchCluster(); // And remove all children; expect all addresses to go away cluster.resize(0); assertEventuallyAddressesMatchCluster(); }
@Test public void testRemoveSensors() throws Exception { entity.getMutableEntityType().removeSensor(SENSOR_ADDED.getName()); entity.getMutableEntityType().removeSensor(POLICY_ADDED.getName()); assertEquals(entity.getEntityType().getSensors(), MutableSet.builder().addAll(DEFAULT_SENSORS).remove(SENSOR_ADDED).remove(POLICY_ADDED).build().asUnmodifiable()); final RecordingSensorEventListener<?> listener = this.listener; Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertEquals(Iterables.size(listener.getEvents()), 2); } }); assertEventuallyListenerEventsEqual(ImmutableList.of( BasicSensorEvent.ofUnchecked(SENSOR_REMOVED, entity, SENSOR_ADDED), BasicSensorEvent.ofUnchecked(SENSOR_REMOVED, entity, POLICY_ADDED))); }