Search in sources :

Example 21 with Status

use of org.apache.dubbo.common.status.Status in project dubbo by alibaba.

the class ThreadPoolStatusCheckerTest method statusUnknownTest.

@Test
public void statusUnknownTest() {
    Status status = threadPoolStatusChecker.check();
    Assertions.assertEquals(status.getLevel(), Status.Level.UNKNOWN);
}
Also used : Status(org.apache.dubbo.common.status.Status) Test(org.junit.jupiter.api.Test)

Example 22 with Status

use of org.apache.dubbo.common.status.Status in project dubbo by alibaba.

the class ThreadPoolStatusCheckerTest method statusOkTest.

@Test
public void statusOkTest() {
    int activeCount = 1;
    int maximumPoolSize = 3;
    String portKey = "8888";
    mockThreadPoolExecutor(activeCount, maximumPoolSize, portKey);
    Status status = threadPoolStatusChecker.check();
    Assertions.assertEquals(status.getLevel(), Status.Level.OK);
    Assertions.assertEquals(status.getMessage(), "Pool status:OK, max:" + maximumPoolSize + ", core:0, largest:0, active:" + activeCount + ", task:0, service port: " + portKey);
    destroy(portKey);
}
Also used : Status(org.apache.dubbo.common.status.Status) Test(org.junit.jupiter.api.Test)

Example 23 with Status

use of org.apache.dubbo.common.status.Status in project dubbo by alibaba.

the class ServerStatusChecker method check.

@Override
public Status check() {
    List<ProtocolServer> servers = DubboProtocol.getDubboProtocol().getServers();
    if (servers == null || servers.isEmpty()) {
        return new Status(Status.Level.UNKNOWN);
    }
    Status.Level level = Status.Level.OK;
    StringBuilder buf = new StringBuilder();
    for (ProtocolServer protocolServer : servers) {
        RemotingServer server = protocolServer.getRemotingServer();
        if (!server.isBound()) {
            level = Status.Level.ERROR;
            buf.setLength(0);
            buf.append(server.getLocalAddress());
            break;
        }
        if (buf.length() > 0) {
            buf.append(",");
        }
        buf.append(server.getLocalAddress());
        buf.append("(clients:");
        buf.append(server.getChannels().size());
        buf.append(")");
    }
    return new Status(level, buf.toString());
}
Also used : Status(org.apache.dubbo.common.status.Status) ProtocolServer(org.apache.dubbo.rpc.ProtocolServer) RemotingServer(org.apache.dubbo.remoting.RemotingServer)

Example 24 with Status

use of org.apache.dubbo.common.status.Status in project dubbo by alibaba.

the class StatusUtilsTest method testGetSummaryStatus2.

@Test
public void testGetSummaryStatus2() throws Exception {
    Status status1 = new Status(Status.Level.WARN);
    Status status2 = new Status(Status.Level.OK);
    Map<String, Status> statuses = new HashMap<String, Status>();
    statuses.put("status1", status1);
    statuses.put("status2", status2);
    Status status = StatusUtils.getSummaryStatus(statuses);
    assertThat(status.getLevel(), is(Status.Level.WARN));
    assertThat(status.getMessage(), containsString("status1"));
    assertThat(status.getMessage(), not(containsString("status2")));
}
Also used : Status(org.apache.dubbo.common.status.Status) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Test(org.junit.jupiter.api.Test)

Example 25 with Status

use of org.apache.dubbo.common.status.Status in project dubbo by alibaba.

the class SpringStatusCheckerTest method testWithoutLifeCycleRunning.

@Test
public void testWithoutLifeCycleRunning() {
    SpringExtensionFactory.clearContexts();
    ApplicationLifeCycle applicationLifeCycle = mock(ApplicationLifeCycle.class);
    new ServiceBean<Object>().setApplicationContext(applicationLifeCycle);
    given(applicationLifeCycle.isRunning()).willReturn(false);
    Status status = springStatusChecker.check();
    assertThat(status.getLevel(), is(Status.Level.ERROR));
}
Also used : Status(org.apache.dubbo.common.status.Status) Test(org.junit.jupiter.api.Test)

Aggregations

Status (org.apache.dubbo.common.status.Status)27 Test (org.junit.jupiter.api.Test)19 HashMap (java.util.HashMap)7 DataSource (javax.sql.DataSource)4 Connection (java.sql.Connection)3 Map (java.util.Map)3 Registry (org.apache.dubbo.registry.Registry)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)3 Method (java.lang.reflect.Method)2 StatusChecker (org.apache.dubbo.common.status.StatusChecker)2 RegistryStatusChecker (org.apache.dubbo.registry.status.RegistryStatusChecker)2 ApplicationContext (org.springframework.context.ApplicationContext)2 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)2 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1