Package org.apache.sling.hc.util

Examples of org.apache.sling.hc.util.FormattingResultLog


        log.info("Activated, logins={}", logins);
    }

    @Override
    public Result execute() {
        final FormattingResultLog resultLog = new FormattingResultLog();
        int checked=0;
        int failures=0;

        for(String login : logins) {
            final String [] parts = login.split(":");
            if(parts.length != 2) {
                resultLog.warn("Expected login in the form username:password, got [{}]", login);
                continue;
            }
            checked++;
            final String username = parts[0].trim();
            final String password = parts[1].trim();
            final Credentials creds = new SimpleCredentials(username, password.toCharArray());
            Session s = null;
            try {
                s = repository.login(creds);
                if(s != null) {
                    failures++;
                    resultLog.warn("Login as [{}] succeeded, was expecting it to fail", username);
                } else {
                    resultLog.debug("Login as [{}] didn't throw an Exception but returned null Session", username);
                }
            } catch(RepositoryException re) {
                resultLog.debug("Login as [{}] failed, as expected", username);
            } finally {
                if(s != null) {
                    s.logout();
                }
            }
        }

        if(checked==0) {
            resultLog.warn("Did not check any logins, configured logins={}", logins);
        } else if(failures != 0){
            resultLog.warn("Checked {} logins, {} failures", checked, failures);
        } else {
            resultLog.debug("Checked {} logins, all successful", checked, failures);
        }
        return new Result(resultLog);
    }
View Full Code Here


        log.info("Activated, paths={}", Arrays.asList(paths));
    }

    @Override
    public Result execute() {
        final FormattingResultLog resultLog = new FormattingResultLog();

        ResourceResolver resolver = null;
        int checked = 0;
        int failed = 0;
        String lastPath = null;

        try {
            resolver = resolverFactory.getAdministrativeResourceResolver(null);
            for(String p : paths) {
                lastPath = p;
                final PathSpec ps = new PathSpec(p, resultLog);
                final HttpServletRequest request = new InternalRequest(ps.path);
                final InternalResponse response = new InternalResponse();
                requestProcessor.processRequest(request, response, resolver);
                final int status = response.getStatus();
                if(status != ps.status) {
                    failed++;
                    resultLog.warn("[{}] returns status {}, expected {}", new Object[] { ps.path, status, ps.status });
                } else {
                    resultLog.debug("[{}] returns status {} as expected", ps.path, status);
                }
                checked++;
            }
        } catch(Exception e) {
            resultLog.warn("Exception while executing request [{}]: {}", lastPath, e);
        } finally {
            if(resolver != null) {
                resolver.close();
            }
        }

        if(checked == 0) {
            resultLog.warn("No paths checked, empty paths list?");
        } else {
            resultLog.debug("{} paths checked, {} failures", checked, failed);
        }

        return new Result(resultLog);
    }
View Full Code Here

        log.info("Activated with TestSelector={}", testSelector);
    }
   
    public Result execute() {
        final String extension ="json";
        final FormattingResultLog resultLog = new FormattingResultLog();
        final CustomRunListener listener = new CustomRunListener(resultLog);
        final Renderer r = new CustomRenderer(listener, extension, resultLog);
        final Collection<String> testNames = testsManager.getTestNames(testSelector);
        if(testNames.isEmpty()) {
            resultLog.warn("No tests found for selector {}", testSelector);
        } else {
            try {
                testsManager.executeTests(testNames, r, testSelector);
                if(listener.nTests == 0) {
                    resultLog.warn("No tests executed by {}", testSelector);
                }
            } catch(Exception e) {
                resultLog.warn("Exception while executing tests (" + testSelector + ")" + e);
            }
        }
       
        return new Result(resultLog);
    }
View Full Code Here

        log.debug("{} deactivated", this);
    }
   
    @Override
    public Result execute() {
        final FormattingResultLog resultLog = new FormattingResultLog();
        try {
            final long randomDelay = (long)(Math.random() * (maxExecutionTime - minExecutionTime));
            final long toSleep = minExecutionTime + randomDelay;
            resultLog.debug("Executing {} will last {} msec", this, toSleep);
            Thread.sleep(toSleep);
        } catch(InterruptedException iex) {
            resultLog.warn("{} during execution", iex.getClass().getSimpleName());
        }
        final String execMsg = "Done executing, execution counter=" + counter.incrementAndGet();
        resultLog.debug("{}:{}", this, execMsg);
        log.debug("{}:{}", this, execMsg);
        return new Result(resultLog);
    }
View Full Code Here

public class AnnotatedHealthCheckSample implements HealthCheck{

    @Override
    public Result execute() {
        final FormattingResultLog resultLog = new FormattingResultLog();
        resultLog.info("All good at {}", new Date());
        return new Result(resultLog);
    }
View Full Code Here

        }

        final int value =  counter.incrementAndGet();
        log.info("{} - counter set to {}", this, value);
       
        final FormattingResultLog resultLog = new FormattingResultLog();

        resultLog.info("{} - counter value set to {} at {}", this, value, new Date());
        if(value % 2 != 0) {
            resultLog.warn("Counter value ({}) is not even", value);
        }
        return new Result(resultLog);
    }
View Full Code Here

                mockBundle(false, true),
                mockBundle(true, false)
        };
        Mockito.when(ctx.getBundles()).thenReturn(bundles);
       
        final FormattingResultLog resultLog = new FormattingResultLog();
        final OsgiScriptBindingsProvider.OsgiBinding b = new OsgiScriptBindingsProvider.OsgiBinding(ctx, resultLog);
        assertEquals(1, b.inactiveBundlesCount());
    }
View Full Code Here

public class JmxScriptBindingsProviderTest {
   
    @Test
    public void testJmxAttribute() throws Exception {
        final FormattingResultLog resultLog = new FormattingResultLog();
        final JmxScriptBindingsProvider.AttributeBinding b = new JmxScriptBindingsProvider.AttributeBinding(ManagementFactory.getPlatformMBeanServer(), resultLog);
        final Object value= b.attribute("java.lang:type=ClassLoading", "LoadedClassCount");
        assertNotNull("Expecting non-null attribute value", value);
        assertTrue("Expecting non-empty value", value.toString().length() > 0);
    }
View Full Code Here

                Mockito.when(ref.getProperty(Constants.SERVICE_ID)).thenReturn(random.nextLong());
                Mockito.when(ref.getProperty(HealthCheck.NAME)).thenReturn("someTest");
                final HealthCheck hc = new HealthCheck() {
                    @Override
                    public Result execute() {
                        final FormattingResultLog log = new FormattingResultLog();
                        return new Result(hls.setLog(log));
                    }
                };
                Mockito.when(bc.getService(ref)).thenReturn(hc);
               
View Full Code Here

        if(result != null) {
            // return recursion error
            return result;
        }

        FormattingResultLog resultLog = new FormattingResultLog();
        List<HealthCheckExecutionResult> executionResults = healthCheckExecutor.execute(filterTags);
        resultLog.debug("Executing {} HealthChecks selected by tags {}", executionResults.size(), Arrays.asList(filterTags));
        result = new CompositeResult(resultLog, executionResults);

        return result;
    }
View Full Code Here

TOP

Related Classes of org.apache.sling.hc.util.FormattingResultLog

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.