Java Code Examples for org.apache.brooklyn.core.entity.Entities#deproxy()
The following examples show how to use
org.apache.brooklyn.core.entity.Entities#deproxy() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrooklynNodeTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
private void runTestGeneratesCorrectDownloadUrl(String version, String expectedUrl) throws Exception { // TODO Using BrooklynNodeImpl directly, because want to instantiate a BroolynNodeSshDriver. // Really want to make that easier to test, without going through "wrong" code path for creating entity. BrooklynNode entity = app.addChild(EntitySpec.create(BrooklynNode.class) .configure(BrooklynNode.SUGGESTED_VERSION, version)); BrooklynNodeImpl entityImpl = (BrooklynNodeImpl) Entities.deproxy(entity); ConfigToAttributes.apply(entity); BrooklynNodeSshDriver driver = new BrooklynNodeSshDriver(entityImpl, loc); DownloadResolver resolver = Entities.newDownloader(driver); List<String> urls = resolver.getTargets(); System.out.println("urls=" + urls); assertTrue(urls.contains(expectedUrl), "urls=" + urls); }
Example 2
Source File: CliTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testStopAllApplications() throws Exception { LaunchCommand launchCommand = new Main.LaunchCommand(); ManagementContext mgmt = LocalManagementContextForTests.newInstance(); try { StartableApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(StartableApplication.class).impl(ExampleApp.class)); ExampleApp appImpl = (ExampleApp) Entities.deproxy(app); SimulatedLocation loc = mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class)); app.start(ImmutableList.of(loc)); assertTrue(appImpl.running); launchCommand.stopAllApps(ImmutableList.of(app)); assertFalse(appImpl.running); } finally { // Stopping the app will make app.getManagementContext return the "NonDeploymentManagementContext"; if (mgmt != null) Entities.destroyAll(mgmt); } }
Example 3
Source File: DynamicClusterTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void stoppingTheClusterStopsTheEntity() throws Exception { DynamicCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class) .configure("memberSpec", EntitySpec.create(BlockingEntity.class)) .configure("initialSize", 1)); cluster.start(ImmutableList.of(loc)); TestEntity entity = (TestEntity) Iterables.get(cluster.getMembers(), 0); TestEntityImpl deproxiedEntity = (TestEntityImpl) Entities.deproxy(entity); assertEquals(entity.getCounter().get(), 1); cluster.stop(); // Need to use deproxiedEntity, because entity-proxy would intercept method call, and it // would fail because the entity has been unmanaged. assertEquals(deproxiedEntity.getCounter().get(), 0); }
Example 4
Source File: EntityManagerTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testCreateEntitiesWithDuplicateIdFails() { TestApplication origApp = app; Entity origDeproxiedApp = Entities.deproxy(app); try { TestApplication app2 = ((EntityManagerInternal)entityManager).createEntity(EntitySpec.create(TestApplication.class), Optional.of(app.getId())); Asserts.shouldHaveFailedPreviously("app2="+app2); } catch (IdAlreadyExistsException e) { // success } // Should not have affected the existing app! Entity postApp = entityManager.getEntity(app.getId()); assertSame(postApp, origApp); assertSame(Entities.deproxy(postApp), origDeproxiedApp); }
Example 5
Source File: InternalEntityFactoryTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testCreatesProxy() throws Exception { EntitySpec<Application> spec = EntitySpec.create(Application.class).impl(TestApplicationImpl.class); Application app = factory.createEntity(spec, Optional.absent()); Application proxy = factory.createEntityProxy(spec, app); TestApplicationImpl deproxied = (TestApplicationImpl) Entities.deproxy(proxy); assertTrue(app instanceof TestApplicationImpl, "app="+app); assertFalse(proxy instanceof TestApplicationImpl, "proxy="+proxy); assertTrue(proxy instanceof EntityProxy, "proxy="+proxy); assertTrue(proxy instanceof Application, "proxy="+proxy); assertTrue(deproxied instanceof TestApplicationImpl, "deproxied="+deproxied); assertFalse(deproxied instanceof EntityProxy, "deproxied="+deproxied); }
Example 6
Source File: ActivePartialRebindTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testRebindParentSimple() throws Exception { TestEntity c1 = origApp.addChild(EntitySpec.create(TestEntity.class)); AbstractEntity origAppr = Entities.deproxy(origApp); doPartialRebindOfIds(origApp.getId()); BrooklynObject app2 = origManagementContext.lookup(origApp.getId()); AbstractEntity app2r = Entities.deproxy((Entity)app2); Assert.assertTrue(app2 == origApp, "Proxy instance should be the same: "+app2+" / "+origApp); Assert.assertFalse(app2r == origAppr, "Real instance should NOT be the same: "+app2r+" / "+origAppr); Assert.assertTrue(c1.getManagementSupport().isDeployed()); // check that child of parent is not a new unmanaged entity Entity c1b = origApp.getChildren().iterator().next(); Assert.assertTrue(c1.getManagementSupport().isDeployed()); Assert.assertTrue( ((EntityInternal)c1b).getManagementSupport().isDeployed(), "Not deployed: "+c1b ); }
Example 7
Source File: ProxyEffectorTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testThrowsIfTargetEffectorDoesntExist() { TestEntity a = app.createAndManageChild(EntitySpec.create(TestEntity.class)); ProxyEffector proxyEffector = new ProxyEffector(ImmutableMap.of( AddEffector.EFFECTOR_NAME, "proxy-effector", ProxyEffector.TARGET_ENTITY, a, ProxyEffector.TARGET_EFFECTOR_NAME, "kajnfksjdnfkjsdnf")); EntityInternal b = Entities.deproxy(app.createAndManageChild(EntitySpec.create(BasicEntity.class) .addInitializer(proxyEffector))); try { b.invoke(b.getEffector("proxy-effector"), ImmutableMap.of("arg", "value")) .getUnchecked(Duration.ONE_MINUTE); Asserts.shouldHaveFailedPreviously("expected exception when invoking effector that does not exist"); } catch (Exception e) { Asserts.expectedFailureOfType(e, NoSuchElementException.class); } }
Example 8
Source File: DynamicGroupTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test(groups="Integration") public void testEntityAddedAndRemovedCalledSequentially() throws Exception { final int NUM_CYCLES = 10; DynamicGroup group2 = app.addChild(EntitySpec.create(DynamicGroup.class) .impl(DynamicGroupCheckingEntityAddedAndRemovedSequentially.class) .configure(DynamicGroup.ENTITY_FILTER, Predicates.instanceOf(TestEntity.class))); for (int i = 0; i < NUM_CYCLES; i++) { TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); Entities.unmanage(entity); } final DynamicGroupCheckingEntityAddedAndRemovedSequentially group2impl = (DynamicGroupCheckingEntityAddedAndRemovedSequentially) Entities.deproxy(group2); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertTrue(group2impl.notificationCount.get() == (NUM_CYCLES*2) || group2impl.exceptions.size() > 0); }}); if (group2impl.exceptions.size() > 0) { throw group2impl.exceptions.get(0); } assertEquals(group2impl.notificationCount.get(), NUM_CYCLES*2); }
Example 9
Source File: MementoGeneratorsPerformanceTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test(groups={"Live", "Acceptance"}) public void testGenerateEntityMemento() throws Exception { int numIterations = numIterations(); double minRatePerSec = 10 * PERFORMANCE_EXPECTATION; // Create an entity with lots of config/parameters, and sensors Map<ConfigKey<?>, String> config = Maps.newLinkedHashMap(); List<BasicSpecParameter<?>> params = Lists.newArrayList(); for (int i = 0; i < 100; i++) { ConfigKey<String> key = ConfigKeys.newStringConfigKey("myparam"+i); params.add(new BasicSpecParameter<String>("mylabel"+i, false, key)); config.put(key, "val"+i); } Entity entity = app.addChild(EntitySpec.create(TestEntity.class) .configure(TestEntity.CONF_NAME, "myname") .configure(config) .parametersAdd(params) .tags(ImmutableList.<Object>of("tag1", "tag2")) .enricher(EnricherSpec.create(TestEnricher.class)) .policy(PolicySpec.create(TestPolicy.class))); for (int i = 0; i < 100; i++) { AttributeSensor<String> sensor = Sensors.newStringSensor("mysensor"+i); entity.sensors().set(sensor, "valsensor"+i); } final Entity deproxiedEntity = Entities.deproxy(entity); // Run the performance test measure(PerformanceTestDescriptor.create() .summary("mementosGenerators.newBasicMemento(entity)") .iterations(numIterations) .minAcceptablePerSecond(minRatePerSec) .job(new Runnable() { @Override public void run() { MementosGenerators.newBasicMemento(deproxiedEntity); }})); }
Example 10
Source File: ActivePartialRebindTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testRebindChildSimple() throws Exception { TestEntity c1 = origApp.addChild(EntitySpec.create(TestEntity.class)); AbstractEntity c1r = Entities.deproxy(c1); doPartialRebindOfIds(c1.getId()); BrooklynObject c2 = origManagementContext.lookup(c1.getId()); AbstractEntity c2r = Entities.deproxy((Entity)c2); Assert.assertTrue(c2 == c1, "Proxy instance should be the same: "+c1+" / "+c2); Assert.assertFalse(c2r == c1r, "Real instance should NOT be the same: "+c1r+" / "+c2r); }
Example 11
Source File: ProxyEffectorTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testHappyPath() { TestEntity a = app.createAndManageChild(EntitySpec.create(TestEntity.class)); ProxyEffector proxyEffector = new ProxyEffector(ImmutableMap.of( AddEffector.EFFECTOR_NAME, "proxy-effector", ProxyEffector.TARGET_ENTITY, a, ProxyEffector.TARGET_EFFECTOR_NAME, "identityEffector")); // BasicEntity doesn't have an identityEffector. EntityInternal b = Entities.deproxy(app.createAndManageChild(EntitySpec.create(BasicEntity.class) .addInitializer(proxyEffector))); Object output = b.invoke(b.getEffector("proxy-effector"), ImmutableMap.of("arg", "value")) .getUnchecked(Duration.ONE_MINUTE); assertEquals(output, "value"); }
Example 12
Source File: SystemServiceEnricherTest.java From brooklyn-server with Apache License 2.0 | 4 votes |
private String getPidFile(VanillaSoftwareProcess proc) { VanillaSoftwareProcessImpl impl = (VanillaSoftwareProcessImpl)Entities.deproxy(proc); return ((VanillaSoftwareProcessSshDriver)impl.getDriver()).getPidFile(); }
Example 13
Source File: LocalEntityManager.java From brooklyn-server with Apache License 2.0 | 4 votes |
private Entity deproxyIfNecessary(Entity e) { return (e instanceof AbstractEntity) ? e : Entities.deproxy(e); }
Example 14
Source File: DynamicGroupTest.java From brooklyn-server with Apache License 2.0 | 4 votes |
@Test public void testDoesNotDeadlockOnUnmanageWhileOtherMemberBeingAdded() throws Exception { final List<Entity> membersAdded = new CopyOnWriteArrayList<Entity>(); final DynamicGroup group2 = app.addChild(EntitySpec.create(DynamicGroup.class) .impl(DynamicGroupTestingUnmanageWhileOtherMemberBeingAdded.class) .configure(DynamicGroup.MEMBER_DELEGATE_CHILDREN, true)); DynamicGroupTestingUnmanageWhileOtherMemberBeingAdded group2impl = (DynamicGroupTestingUnmanageWhileOtherMemberBeingAdded) Entities.deproxy(group2); final CountDownLatch removingMemberReachedLatch = group2impl.removingMemberReachedLatch; final CountDownLatch addingMemberReachedLatch = group2impl.addingMemberReachedLatch; final CountDownLatch addingMemberContinueLatch = group2impl.addingMemberContinueLatch; final AtomicBoolean addingMemberDoLatching = group2impl.addingMemberDoLatching; app.subscriptions().subscribe(group2, AbstractGroup.MEMBER_ADDED, new SensorEventListener<Entity>() { @Override public void onEvent(SensorEvent<Entity> event) { membersAdded.add(event.getValue()); }}); final TestEntity e2 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); final TestEntity e3 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); group2.addMember(e2); assertContainsEventually(membersAdded, e2); addingMemberDoLatching.set(true); Thread t1 = new Thread(new Runnable() { @Override public void run() { try { addingMemberReachedLatch.await(); } catch (InterruptedException e) { throw Exceptions.propagate(e); } Entities.unmanage(e2); }}); Thread t2 = new Thread(new Runnable() { @Override public void run() { group2.addMember(e3); }}); t1.start(); t2.start(); try { removingMemberReachedLatch.await(); addingMemberContinueLatch.countDown(); t1.join(TIMEOUT_MS); t2.join(TIMEOUT_MS); assertFalse(t1.isAlive()); assertFalse(t2.isAlive()); } finally { t1.interrupt(); t2.interrupt(); } }