@Test public void testGetEffector() throws Exception { TestEntity entity2 = app.createAndManageChild(EntitySpecs.spec(TestEntity.class)); Effector<?> effector = entity2.getEntityType().getEffector("myEffector"); Effector<?> effector2 = entity2.getEntityType().getEffector("identityEffector", Object.class); assertEquals(effector.getName(), "myEffector"); assertEquals(effector2.getName(), "identityEffector"); }
@Override public void init() { ConfigToAttributes.apply(this, BROKER_SPEC); ConfigToAttributes.apply(this, ZOOKEEPER); ConfigToAttributes.apply(this, ZOOKEEPER_SPEC); log.debug("creating zookeeper child for {}", this); Zookeeper zookeeper = getAttribute(ZOOKEEPER); if (zookeeper == null) { EntitySpec<KafkaZookeeper> zookeeperSpec = getAttribute(ZOOKEEPER_SPEC); if (zookeeperSpec == null) { log.debug("creating zookeeper using default spec for {}", this); zookeeperSpec = EntitySpecs.spec(KafkaZookeeper.class); setAttribute(ZOOKEEPER_SPEC, zookeeperSpec); } else { log.debug("creating zookeeper using custom spec for {}", this); } zookeeper = addChild(zookeeperSpec); if (Entities.isManaged(this)) Entities.manage(zookeeper); setAttribute(ZOOKEEPER, zookeeper); } log.debug("creating cluster child for {}", this); EntitySpec<KafkaBroker> brokerSpec = getAttribute(BROKER_SPEC); if (brokerSpec == null) { log.debug("creating default broker spec for {}", this); brokerSpec = EntitySpecs.spec(KafkaBroker.class); setAttribute(BROKER_SPEC, brokerSpec); } // Relies on initialSize being inherited by DynamicCluster, because key id is identical // We add the zookeeper configuration to the KafkaBroker specification here DynamicCluster cluster = addChild( EntitySpecs.spec(DynamicCluster.class) .configure( "memberSpec", EntitySpecs.wrapSpec(brokerSpec).configure(KafkaBroker.ZOOKEEPER, zookeeper))); if (Entities.isManaged(this)) Entities.manage(cluster); setAttribute(CLUSTER, cluster); }
@Test(groups = "Integration") public void testJavaStartStopSshDriverStartsAndStopsApp() { final MyEntity entity = app.createAndManageChild(EntitySpecs.spec(MyEntity.class)); app.start(ImmutableList.of(localhost)); Asserts.succeedsEventually( MutableMap.of("timeout", TIMEOUT_MS), new Runnable() { public void run() { assertTrue(entity.getAttribute(SoftwareProcess.SERVICE_UP)); } }); entity.stop(); assertFalse(entity.getAttribute(SoftwareProcess.SERVICE_UP)); }
@Test public void testGetEffectors() throws Exception { TestEntity entity2 = app.createAndManageChild(EntitySpecs.spec(TestEntity.class)); Set<Effector<?>> effectors = entity2.getEntityType().getEffectors(); class MatchesNamePredicate implements Predicate<Effector<?>> { private final String name; public MatchesNamePredicate(String name) { this.name = name; } @Override public boolean apply(@Nullable Effector<?> input) { return name.equals(input.getName()); } }; assertNotNull(Iterables.find(effectors, new MatchesNamePredicate("myEffector")), null); assertNotNull(Iterables.find(effectors, new MatchesNamePredicate("identityEffector")), null); }
@Test public void testGetSimpleName() throws Exception { TestEntity entity2 = app.createAndManageChild(EntitySpecs.spec(TestEntity.class)); assertEquals(entity2.getEntityType().getSimpleName(), TestEntity.class.getSimpleName()); }