aboutsummaryrefslogtreecommitdiffstats
path: root/container-disc/src/test/java/com/yahoo/container/jdisc/ContainerThreadFactoryTest.java
blob: d46771e3c95ad1f84789bfb45efebe55a9d99d4b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.jdisc;

import com.yahoo.container.jdisc.metric.MetricConsumerProvider;
import com.yahoo.jdisc.application.ContainerThread;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.util.concurrent.ThreadFactory;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

/**
 * @author Simon Thoresen Hult
 */
public class ContainerThreadFactoryTest {

    @Test
    void requireThatMetricConsumerProviderCanNotBeNull() {
        try {
            new ContainerThreadFactory(null);
            fail();
        } catch (NullPointerException e) {

        }
    }

    @Test
    void requireThatThreadsCreatedAreJDiscContainerThreads() {
        assertEquals(ContainerThread.class,
                new ContainerThreadFactory(Mockito.mock(MetricConsumerProvider.class))
                        .newThread(Mockito.mock(Runnable.class))
                        .getClass());
    }

    @Test
    void requireThatThreadFactoryCallsProvider() {
        MetricConsumerProvider provider = Mockito.mock(MetricConsumerProvider.class);
        ThreadFactory factory = new ContainerThreadFactory(provider);
        factory.newThread(Mockito.mock(Runnable.class));
        Mockito.verify(provider, Mockito.times(1)).newInstance();
        factory.newThread(Mockito.mock(Runnable.class));
        Mockito.verify(provider, Mockito.times(2)).newInstance();
    }
}