@Override public void run() { Asserts.assertTrue(predicate.apply(entity), "predicate " + predicate + " unsatisfied for "+ entity); }}); }
@Override public void run() { Asserts.assertTrue(changed.get(), entity + " -> " + attribute + " not changed from "+origValue); }}); } finally {
public static <T> T assertAttribute(final Entity entity, final AttributeSensor<T> attribute, final Predicate<? super T> predicate) { T val = entity.getAttribute(attribute); Asserts.assertTrue(predicate.apply(val), "attribute="+attribute+"; val=" + val); return val; }
public static void assertEqualsIgnoringOrder(Iterable<?> actual, Iterable<?> expected, boolean logDuplicates, String errmsg) { Set<?> actualSet = Sets.newLinkedHashSet(actual); Set<?> expectedSet = Sets.newLinkedHashSet(expected); Set<?> extras = Sets.difference(actualSet, expectedSet); Set<?> missing = Sets.difference(expectedSet, actualSet); List<Object> duplicates = Lists.newArrayList(actual); for (Object a : actualSet) { duplicates.remove(a); } String fullErrmsg = "extras="+extras+"; missing="+missing + (logDuplicates ? "; duplicates="+MutableSet.copyOf(duplicates) : "") +"; actualSize="+Iterables.size(actual)+"; expectedSize="+Iterables.size(expected) +"; actual="+actual+"; expected="+expected+"; "+errmsg; assertTrue(extras.isEmpty(), fullErrmsg); assertTrue(missing.isEmpty(), fullErrmsg); assertTrue(Iterables.size(actual) == Iterables.size(expected), fullErrmsg); assertTrue(actualSet.equals(expectedSet), fullErrmsg); // should be covered by extras/missing/size test }
public static void assertContentMatches(String url, String regex) { String contents = HttpTool.getContent(url); Asserts.assertNotNull(contents); Asserts.assertTrue(contents.matches(regex), "Contents does not match expected regex ("+regex+"): "+contents); }
public static void assertErrorContentContainsText(final String url, final String phrase, final String ...additionalPhrases) { try { String contents = HttpTool.getErrorContent(url); Asserts.assertTrue(contents != null && contents.length() > 0); for (String text: Lists.asList(phrase, additionalPhrases)) { if (!contents.contains(text)) { LOG.warn("CONTENTS OF URL "+url+" MISSING TEXT: "+text+"\n"+contents); Asserts.fail("URL "+url+" does not contain text: "+text); } } } catch (Exception e) { throw propagateAsAssertionError(e); } }
public static void assertContentContainsText(final String url, final String phrase, final String ...additionalPhrases) { try { String contents = HttpTool.getContent(url); Asserts.assertTrue(contents != null && contents.length() > 0); for (String text: Lists.asList(phrase, additionalPhrases)) { if (!contents.contains(text)) { LOG.warn("CONTENTS OF URL "+url+" MISSING TEXT: "+text+"\n"+contents); Asserts.fail("URL "+url+" does not contain text: "+text); } } } catch (Exception e) { throw propagateAsAssertionError(e); } }
public static void assertErrorContentNotContainsText(final String url, final String phrase, final String ...additionalPhrases) { try { String err = HttpTool.getErrorContent(url); Asserts.assertTrue(err != null); for (String text: Lists.asList(phrase, additionalPhrases)) { if (err.contains(text)) { LOG.warn("CONTENTS OF URL "+url+" HAS TEXT: "+text+"\n"+err); Asserts.fail("URL "+url+" contain text: "+text); } } } catch (Exception e) { throw propagateAsAssertionError(e); } }
public static void assertContentNotContainsText(final String url, final String phrase, final String ...additionalPhrases) { try { String contents = HttpTool.getContent(url); Asserts.assertTrue(contents != null); for (String text: Lists.asList(phrase, additionalPhrases)) { if (contents.contains(text)) { LOG.warn("CONTENTS OF URL "+url+" HAS TEXT: "+text+"\n"+contents); Asserts.fail("URL "+url+" contain text: "+text); } } } catch (Exception e) { throw propagateAsAssertionError(e); } }
private void assertPasswordOnlyContains(Entity entity, AttributeSensor<String> password, String acceptableChars) { String attribute_2 = entity.getAttribute(password); for (char c : attribute_2.toCharArray()) { Asserts.assertTrue(acceptableChars.indexOf(c) != -1); } }
private void checkRole(String du, String role, String attrib) { List<String> lines = ImmutableList.copyOf(Splitter.on("\n").trimResults().split(du)); boolean found = false; for (String line : lines) { if (line.startsWith(role)) { assertTrue(line.matches(".*"+attrib+".*"), "du="+du); found = true; break; } } if (!found) { fail("Role "+role+" not found in du="+du); } du.split("\n"); } }
public void run() { Asserts.assertEquals(outerTasks.size(), NUM_CALLS); for (Task<?> task : outerTasks) { Asserts.assertTrue(task.isDone()); Asserts.assertTrue(task.isCancelled()); } } });
@Test public void testHasOsgiManifestWhenValidManifest() throws Exception { Map<String, String> manifest = ImmutableMap.of(Attributes.Name.MANIFEST_VERSION.toString(), "1.2.3", Constants.BUNDLE_SYMBOLICNAME, "myname"); generatedJar = bundleMaker.copyAddingManifest(emptyJar, manifest); assertTrue(bundleMaker.hasOsgiManifest(generatedJar)); }
@Test(groups = "Integration") public void testCanStartAndStop() throws Exception { MongoDBConfigServer entity = app.createAndManageChild(EntitySpec.create(MongoDBConfigServer.class) .configure(MongoDBServer.MONGODB_CONF_TEMPLATE_URL, "classpath:///test-mongodb-configserver.conf")); app.start(ImmutableList.of(localhostProvisioningLocation)); EntityAsserts.assertAttributeEqualsEventually(entity, Startable.SERVICE_UP, true); Asserts.assertTrue(MongoDBTestHelper.isConfigServer(entity), "Server is not a config server"); entity.stop(); assertFalse(entity.getAttribute(Startable.SERVICE_UP)); } }
@Test public void testGroupDefaults() throws Exception { group = app.addChild(EntitySpec.create(SequenceGroup.class)); createTestEntities(); app.start(ImmutableList.of(loc1)); assertAttributeEqualsEventually(group, SequenceGroup.RUNNING, true); assertAttribute(group, SequenceGroup.SEQUENCE_VALUE, Predicates.isNull()); assertTrue(group.getMembers().isEmpty()); }
@Test public void testScheduledEffectorFiresImmediately() { TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class) .policy(PolicySpec.create(ScheduledEffectorPolicy.class) .configure(ScheduledEffectorPolicy.EFFECTOR, "myEffector") .configure(ScheduledEffectorPolicy.EFFECTOR_ARGUMENTS, ImmutableMap.of()) .configure(ScheduledEffectorPolicy.TIME, "immediately") .configure(PeriodicEffectorPolicy.START_SENSOR, START))); Policy policy = Iterables.tryFind(entity.policies(), Predicates.instanceOf(ScheduledEffectorPolicy.class)).orNull(); Asserts.assertNotNull(policy); Asserts.assertTrue(entity.getCallHistory().isEmpty()); Asserts.assertFalse(policy.config().get(ScheduledEffectorPolicy.RUNNING)); entity.sensors().set(START, Boolean.TRUE); assertConfigEqualsEventually(policy, ScheduledEffectorPolicy.RUNNING, true); assertCallHistoryContainsEventually(entity, "myEffector"); }
@Test public void testPeriodicEffectorFires() { TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class) .policy(PolicySpec.create(PeriodicEffectorPolicy.class) .configure(PeriodicEffectorPolicy.EFFECTOR, "myEffector") .configure(PeriodicEffectorPolicy.EFFECTOR_ARGUMENTS, ImmutableMap.of()) .configure(PeriodicEffectorPolicy.PERIOD, Duration.ONE_MILLISECOND) .configure(PeriodicEffectorPolicy.TIME, "immediately") .configure(PeriodicEffectorPolicy.START_SENSOR, START))); Policy policy = Iterables.tryFind(entity.policies(), Predicates.instanceOf(PeriodicEffectorPolicy.class)).orNull(); Asserts.assertNotNull(policy); Asserts.assertTrue(entity.getCallHistory().isEmpty()); Asserts.assertFalse(policy.config().get(PeriodicEffectorPolicy.RUNNING)); entity.sensors().set(START, Boolean.TRUE); assertConfigEqualsEventually(policy, PeriodicEffectorPolicy.RUNNING, true); assertCallHistoryEventually(entity, "myEffector", 2); }
@Test public void testScheduledEffectorFiresOnSensor() { TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class) .policy(PolicySpec.create(ScheduledEffectorPolicy.class) .configure(ScheduledEffectorPolicy.EFFECTOR, "myEffector") .configure(ScheduledEffectorPolicy.EFFECTOR_ARGUMENTS, ImmutableMap.of()) .configure(ScheduledEffectorPolicy.START_SENSOR, START))); Policy policy = Iterables.tryFind(entity.policies(), Predicates.instanceOf(ScheduledEffectorPolicy.class)).orNull(); Asserts.assertNotNull(policy); Asserts.assertTrue(entity.getCallHistory().isEmpty()); Asserts.assertFalse(policy.config().get(ScheduledEffectorPolicy.RUNNING)); entity.sensors().set(START, Boolean.TRUE); assertConfigEqualsEventually(policy, ScheduledEffectorPolicy.RUNNING, true); assertCallHistoryNeverContinually(entity, "myEffector"); entity.sensors().set(ScheduledEffectorPolicy.INVOKE_IMMEDIATELY, Boolean.TRUE); assertCallHistoryContainsEventually(entity, "myEffector"); } }
@Test(groups="Integration") public void testScheduledEffectorFiresAfterDelay() { TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class) .policy(PolicySpec.create(ScheduledEffectorPolicy.class) .configure(ScheduledEffectorPolicy.EFFECTOR, "myEffector") .configure(ScheduledEffectorPolicy.EFFECTOR_ARGUMENTS, ImmutableMap.of()) .configure(ScheduledEffectorPolicy.WAIT, Duration.FIVE_SECONDS) .configure(ScheduledEffectorPolicy.START_SENSOR, START))); Policy policy = Iterables.tryFind(entity.policies(), Predicates.instanceOf(ScheduledEffectorPolicy.class)).orNull(); Asserts.assertNotNull(policy); Asserts.assertTrue(entity.getCallHistory().isEmpty()); Asserts.assertFalse(policy.config().get(ScheduledEffectorPolicy.RUNNING)); entity.sensors().set(START, Boolean.TRUE); assertConfigEqualsEventually(policy, ScheduledEffectorPolicy.RUNNING, true); assertCallHistoryNeverContinually(entity, "myEffector"); Time.sleep(Duration.seconds(5)); assertCallHistoryContainsEventually(entity, "myEffector"); }
@Test(groups="Integration") public void testPeriodicEffectorFiresAfterDelay() { TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class) .policy(PolicySpec.create(PeriodicEffectorPolicy.class) .configure(PeriodicEffectorPolicy.EFFECTOR, "myEffector") .configure(PeriodicEffectorPolicy.EFFECTOR_ARGUMENTS, ImmutableMap.of()) .configure(PeriodicEffectorPolicy.PERIOD, Duration.ONE_MILLISECOND) .configure(PeriodicEffectorPolicy.WAIT, Duration.FIVE_SECONDS) .configure(PeriodicEffectorPolicy.START_SENSOR, START))); Policy policy = Iterables.tryFind(entity.policies(), Predicates.instanceOf(PeriodicEffectorPolicy.class)).orNull(); Asserts.assertNotNull(policy); Asserts.assertTrue(entity.getCallHistory().isEmpty()); Asserts.assertFalse(policy.config().get(PeriodicEffectorPolicy.RUNNING)); entity.sensors().set(START, Boolean.TRUE); assertConfigEqualsEventually(policy, PeriodicEffectorPolicy.RUNNING, true); assertCallHistoryNeverContinually(entity, "myEffector"); Time.sleep(Duration.seconds(5)); assertCallHistoryEventually(entity, "myEffector", 2); }