Search in sources :

Example 1 with ExtendedHealthCheckExecutor

use of org.apache.sling.hc.core.impl.executor.ExtendedHealthCheckExecutor in project sling by apache.

the class HealthCheckMBeanTest method testBean.

@Test
public void testBean() throws Exception {
    final ServiceReference ref = new ServiceReference() {

        @Override
        public boolean isAssignableTo(Bundle bundle, String className) {
            return false;
        }

        @Override
        public Bundle[] getUsingBundles() {
            return null;
        }

        @Override
        public String[] getPropertyKeys() {
            return null;
        }

        @Override
        public Object getProperty(String key) {
            return null;
        }

        @Override
        public Bundle getBundle() {
            return null;
        }

        @Override
        public int compareTo(Object reference) {
            return 0;
        }
    };
    final HealthCheckMBean mbean = new HealthCheckMBean(ref, new ExtendedHealthCheckExecutor() {

        @SuppressWarnings("deprecation")
        @Override
        public List<HealthCheckExecutionResult> execute(String... tags) {
            return null;
        }

        @Override
        public HealthCheckExecutionResult execute(ServiceReference ref) {
            // TODO Auto-generated method stub
            return new HealthCheckExecutionResult() {

                @Override
                public Result getHealthCheckResult() {
                    // TODO Auto-generated method stub
                    return testHealthCheck.execute();
                }

                @Override
                public HealthCheckMetadata getHealthCheckMetadata() {
                    // TODO Auto-generated method stub
                    return null;
                }

                @Override
                public Date getFinishedAt() {
                    // TODO Auto-generated method stub
                    return null;
                }

                @Override
                public long getElapsedTimeInMs() {
                    // TODO Auto-generated method stub
                    return 0;
                }

                @Override
                public boolean hasTimedOut() {
                    // TODO Auto-generated method stub
                    return false;
                }
            };
        }

        @SuppressWarnings("deprecation")
        @Override
        public List<HealthCheckExecutionResult> execute(HealthCheckExecutionOptions options, String... tags) {
            return null;
        }

        @Override
        public List<HealthCheckExecutionResult> execute(HealthCheckSelector selector) {
            return null;
        }

        @Override
        public List<HealthCheckExecutionResult> execute(HealthCheckSelector selector, HealthCheckExecutionOptions options) {
            return null;
        }
    });
    final ObjectName name = new ObjectName(OBJECT_NAME);
    jmxServer.registerMBean(mbean, name);
    try {
        resultOk = true;
        assertJmxValue(OBJECT_NAME, "ok", "true", true);
        Thread.sleep(1500);
        resultOk = false;
        assertJmxValue(OBJECT_NAME, "ok", "true", false);
        Thread.sleep(1500);
        assertJmxValue(OBJECT_NAME, "log", "contains message=Result is not ok!", true);
    } finally {
        jmxServer.unregisterMBean(name);
    }
}
Also used : HealthCheckMetadata(org.apache.sling.hc.util.HealthCheckMetadata) Bundle(org.osgi.framework.Bundle) ExtendedHealthCheckExecutor(org.apache.sling.hc.core.impl.executor.ExtendedHealthCheckExecutor) Date(java.util.Date) ServiceReference(org.osgi.framework.ServiceReference) Result(org.apache.sling.hc.api.Result) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult) ObjectName(javax.management.ObjectName) HealthCheckSelector(org.apache.sling.hc.api.execution.HealthCheckSelector) HealthCheckExecutionOptions(org.apache.sling.hc.api.execution.HealthCheckExecutionOptions) List(java.util.List) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult) Test(org.junit.Test)

Aggregations

Date (java.util.Date)1 List (java.util.List)1 ObjectName (javax.management.ObjectName)1 Result (org.apache.sling.hc.api.Result)1 HealthCheckExecutionOptions (org.apache.sling.hc.api.execution.HealthCheckExecutionOptions)1 HealthCheckExecutionResult (org.apache.sling.hc.api.execution.HealthCheckExecutionResult)1 HealthCheckSelector (org.apache.sling.hc.api.execution.HealthCheckSelector)1 ExtendedHealthCheckExecutor (org.apache.sling.hc.core.impl.executor.ExtendedHealthCheckExecutor)1 HealthCheckMetadata (org.apache.sling.hc.util.HealthCheckMetadata)1 Test (org.junit.Test)1 Bundle (org.osgi.framework.Bundle)1 ServiceReference (org.osgi.framework.ServiceReference)1