@Test public void testIfNotEqual() { IfFunctionsTest.checkTF(Functionals.ifNotEquals(false).value("T").defaultValue("F").build(), "T"); }
@Test public void testFunction() { checkTF(IfFunctions.ifNotEquals((Boolean)null).apply(new Function<Boolean, String>() { @Override public String apply(Boolean input) { return input.toString().toUpperCase().substring(0, 1); } }).defaultValue("?"), "?"); }
@Test public void testIfPredicateAndSupplier() { IfFunctionsTest.checkTF(Functionals.ifPredicate(Predicates.equalTo(false)).get(Suppliers.ofInstance("F")) .ifEquals(true).value("T").defaultGet(Suppliers.ofInstance("?")).build(), "?"); }
.computing(Functionals.ifNotEquals(true).value("Management URL not reachable") ) .build());
.computing(Functionals.ifNotEquals(true).value("URL where Brooklyn listens is not answering correctly") ) .build());
.computing(Functionals.ifNotEquals(true).value("URL not reachable")) .build());
.uniqueTag("not-up-unless-url-answers") .from(NGINX_URL_ANSWERS_NICELY) .computing(Functionals.ifNotEquals(true).value("URL where nginx listens is not answering correctly (with expected header)") ) .build()); connectServiceUpIsRunning();
.computing(Functionals.ifNotEquals(true).value("Crate server reports it is not ok.")) .build());
@Override protected Entity createNode(Location loc, Map<?, ?> flags) { MySqlNode node = (MySqlNode) super.createNode(loc, flags); if (!MySqlClusterUtils.IS_MASTER.apply(node)) { ServiceNotUpLogic.updateNotUpIndicator(node, MySqlSlave.SLAVE_HEALTHY, "Replication not started"); addFeed(FunctionFeed.builder() .entity(node) .period(Duration.FIVE_SECONDS) .poll(FunctionPollConfig.forSensor(MySqlSlave.SLAVE_HEALTHY) .callable(new SlaveStateCallable(node)) .checkSuccess(StringPredicates.isNonBlank()) .onSuccess(new SlaveStateParser(node)) .setOnFailure(false) .description("Polls SHOW SLAVE STATUS")) .build()); node.enrichers().add(Enrichers.builder().updatingMap(Attributes.SERVICE_NOT_UP_INDICATORS) .from(MySqlSlave.SLAVE_HEALTHY) .computing(Functionals.ifNotEquals(true).value("Slave replication status is not healthy") ) .build()); } return node; }
@Test public void testIf() { IfFunctionsTest.checkTF(Functionals.ifEquals(false).value("F").ifEquals(true).value("T").defaultValue("?").build(), "?"); }
public static <I> IfFunctionBuilderApplyingFirst<I> ifPredicate(Predicate<? super I> test) { return new IfFunctionBuilderApplyingFirst<I>(test); } public static <I> IfFunctionBuilderApplyingFirst<I> ifEquals(I test) {
@Test public void testIfNoBuilder() { IfFunctionsTest.checkTF(Functionals.ifEquals(false).value("F").ifEquals(true).value("T").defaultValue("?"), "?"); }
@Test public void testNoDefault() { checkTF(IfFunctions.ifEquals(false).value("F").ifEquals(true).value("T").build(), null); }
@Test public void testNoBuilder() { checkTF(IfFunctions.ifEquals(false).value("F").ifEquals(true).value("T").defaultValue("?"), "?"); }
@Test public void testIsImmutableAndSupportsReplace() { IfFunctionBuilder<Boolean, String> f = IfFunctions.ifEquals(false).value("F").ifEquals(true).value("T").defaultValue("?"); IfFunctionBuilder<Boolean, String> f2 = f.ifEquals(false).value("false").defaultValue("X"); IfFunctionBuilder<Boolean, String> f3 = f2.ifEquals(false).value("F"); checkTF(f, "?"); checkTF(f3, "X"); Assert.assertEquals(f2.apply(false), "false"); }
@Test public void testUpdatingMap1() { entity.enrichers().add(Enrichers.builder() .updatingMap(MAP1) .from(LONG1) .computing(Functionals.ifEquals(-1L).value("-1 is not allowed")) .build()); doUpdatingMapChecks(MAP1); }
@Test public void testNotEqual() { checkTF(IfFunctions.ifNotEquals(false).value("T").defaultValue("F").build(), "T"); }
@Test public void testCommonUsage() { checkTF(IfFunctions.ifEquals(false).value("F").ifEquals(true).value("T").defaultValue("?").build(), "?"); }
public <O> IfFunctionBuilder<I,O> value(O value) { return apply(new Functionals.ConstantFunction<I,O>(value, value)); } @SuppressWarnings("unchecked")
private <T> void propagateMasterAttribute(AttributeSensor<T> att) { enrichers().add(Enrichers.builder() .aggregating(att) .publishing(att) .computing(IfFunctions.<Collection<T>>ifPredicate(CollectionFunctionals.notEmpty()) .apply(CollectionFunctionals.firstElement()) .defaultValue(null)) .entityFilter(MySqlClusterUtils.IS_MASTER) .build()); }