org.apache.brooklyn.core.entity.Entities.deproxy()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(117)

本文整理了Java中org.apache.brooklyn.core.entity.Entities.deproxy()方法的一些代码示例,展示了Entities.deproxy()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entities.deproxy()方法的具体详情如下:
包路径:org.apache.brooklyn.core.entity.Entities
类名称:Entities
方法名:deproxy

Entities.deproxy介绍

[英]Unwraps a proxy to retrieve the real item, if available.

Only intended for use in tests and occasional internal usage, e.g. persistence. For normal operations, callers should ensure the method is available on an interface and accessed via the proxy.
[中]展开代理以检索真实项目(如果可用)。
仅用于测试和偶尔的内部使用,例如持久性。对于正常操作,调用方应确保该方法在接口上可用,并通过代理进行访问。

代码示例

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Override
  public BrooklynObject apply(BrooklynObject obj) {
    // entities must be deproxied
    if (obj instanceof Entity) obj = Entities.deproxy((Entity)obj);
    return obj;
  }
}));

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

private Entity deproxyIfNecessary(Entity e) {
  return (e instanceof AbstractEntity) ? e : Entities.deproxy(e);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

private Map<String, EntityMemento> toMementos(Iterable<? extends Entity> entities) {
    Map<String, EntityMemento> result = Maps.newLinkedHashMap();
    for (Entity entity : entities) {
      result.put(entity.getId(), (EntityMemento) MementosGenerators.newBasicMemento(Entities.deproxy(entity)));
    }
    return result;
  }
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-software-base

@Test
public void testFindMaster() {
  List<Entity> nodes = makeTwoNodes();
  Assert.assertEquals(((BrooklynClusterImpl)Entities.deproxy(cluster)).findMasterChild(), nodes.get(0));
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Test
public void testAddConfigKeyThroughEntity() throws Exception{
  Entities.deproxy(entity).configure(ImmutableList.<ConfigKey<?>>of(NEW_CONFIG));
  assertEquals(entity.getEntityType().getConfigKeys(), 
      ImmutableSet.builder().addAll(DEFAULT_CONFIG_KEYS).add(NEW_CONFIG).build());
  
  assertEventuallyListenerEventsEqual(ImmutableList.of(BasicSensorEvent.ofUnchecked(AbstractEntity.CONFIG_KEY_ADDED, entity, NEW_CONFIG)));
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@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);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-software-webapp

/**
 * Stop the given underlying entity, but without our entity instance being told!
 */
protected void killEntityBehindBack(Entity tokill) throws Exception {
  ((SoftwareProcessImpl) Entities.deproxy(tokill)).getDriver().stop();
  // old method of doing this did some dodgy legacy rebind and failed due to too many dangling refs; above is better in any case
  // but TODO we should have some rebind tests for these!
}
/**

代码示例来源:origin: org.apache.brooklyn/brooklyn-software-webapp

/**
 * Stop the given underlying entity, but without our entity instance being told!
 */
protected void killEntityBehindBack(Entity tokill) throws Exception {
  ((SoftwareProcessDriver)((DriverDependentEntity<?>) Entities.deproxy(tokill)).getDriver()).stop();
  // old method of doing this did some dodgy legacy rebind and failed due to too many dangling refs; above is better in any case
  // but TODO we should have some rebind tests for these!
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-software-base

private String getPidFile(VanillaSoftwareProcess proc) {
  VanillaSoftwareProcessImpl impl = (VanillaSoftwareProcessImpl)Entities.deproxy(proc);
  return ((VanillaSoftwareProcessSshDriver)impl.getDriver()).getPidFile();
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@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);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@BeforeMethod(alwaysRun=true)
@Override
public void setUp() throws Exception {
  super.setUp();
  entity = app.addChild(EntitySpec.create(TestEntity.class));
  entityImpl = (TestEntityImpl) Entities.deproxy(entity);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@BeforeMethod(alwaysRun=true)
public void setUp() {
  app = TestApplication.Factory.newManagedInstanceForTests();
  TestEntity entity = app.addChild(EntitySpec.create(TestEntity.class));
  entityImpl = (TestEntityImpl) Entities.deproxy(entity);
  map = new AttributeMap(entityImpl, Collections.synchronizedMap(MutableMap.<Collection<String>,Object>of()));
  executor = Executors.newCachedThreadPool();
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@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);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@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 );
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@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);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-software-base

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);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

private MyEntity newDeproxiedEntity(Map<?, ?> config) {
  Entity result = app.addChild(EntitySpec.create(Entity.class).impl(MyEntity.class)
      .configure(config));
  return (MyEntity) Entities.deproxy(result);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@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");
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@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);
  }
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-software-database

protected void runBuildCreateRoles(Map<String, Map<String, ?>> roles, String expected) throws Exception {
  stubbedMachine = app.getManagementContext().getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
      .configure("sshToolClass", RecordingSshTool.class.getName())
      .configure("address", "1.2.3.4"));
  
  PostgreSqlNode pgsql = app.createAndManageChild(EntitySpec.create(PostgreSqlNode.class)
      .impl(PostgreSqlNodeForTestingImpl.class)
      .configure(PostgreSqlNode.ROLES, roles)
      .location(stubbedMachine));
  
  PostgreSqlNodeForTestingImpl impl = (PostgreSqlNodeForTestingImpl) Entities.deproxy(pgsql);
  PostgreSqlSshDriver driver = (PostgreSqlSshDriver) impl.doInitDriver(stubbedMachine);
  String query = driver.buildCreateRolesQuery();
  assertEquals(query, expected);
}

相关文章