Search in sources :

Example 1 with RunnableScheduledFuture

use of java.util.concurrent.RunnableScheduledFuture in project java-chassis by ServiceComb.

the class TestThreadPoolPublishModelFactory method createDefaultPublishModel.

@Test
public void createDefaultPublishModel() throws JsonProcessingException {
    new Expectations() {

        {
            threadPoolExecutor.getQueue();
            result = queue;
            queue.size();
            result = 10d;
        }
    };
    new MockUp<ScheduledThreadPoolExecutor>() {

        @Mock
        void delayedExecute(RunnableScheduledFuture<?> task) {
        }
    };
    try {
        ThreadPoolMonitor.attach(registry, threadPoolExecutor, "test");
        PolledMeter.update(registry);
        PublishModelFactory factory = new PublishModelFactory(Lists.newArrayList(registry.iterator()));
        DefaultPublishModel model = factory.createDefaultPublishModel();
        Assert.assertEquals("{\"test\":{\"avgTaskCount\":0.0,\"avgCompletedTaskCount\":0.0,\"currentThreadsBusy\":0,\"maxThreads\":0,\"poolSize\":0,\"corePoolSize\":0,\"queueSize\":10,\"rejected\":\"NaN\"}}", JsonUtils.writeValueAsString(model.getThreadPools()));
    } catch (Throwable e) {
        e.printStackTrace();
        Assert.fail("unexpected error happen. " + e.getMessage());
    }
}
Also used : Expectations(mockit.Expectations) RunnableScheduledFuture(java.util.concurrent.RunnableScheduledFuture) MockUp(mockit.MockUp) DefaultPublishModel(org.apache.servicecomb.metrics.core.publish.model.DefaultPublishModel) Test(org.junit.Test)

Aggregations

RunnableScheduledFuture (java.util.concurrent.RunnableScheduledFuture)1 Expectations (mockit.Expectations)1 MockUp (mockit.MockUp)1 DefaultPublishModel (org.apache.servicecomb.metrics.core.publish.model.DefaultPublishModel)1 Test (org.junit.Test)1