blob: 5be1cda4593e27c1be8cf5f7338fb813506d6f04 [file] [log] [blame]
Thomas Vachuska9c17a6d2015-02-17 23:36:43 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onlab.util;
17
18import org.junit.Test;
19import org.onlab.junit.TestTools;
20
21import static org.junit.Assert.*;
22
23/**
24 * Tests of the group thread factory.
25 */
26public class GroupedThreadFactoryTest {
27
28 @Test
29 public void basics() {
30 GroupedThreadFactory a = GroupedThreadFactory.groupedThreadFactory("foo");
31 GroupedThreadFactory b = GroupedThreadFactory.groupedThreadFactory("foo");
32 assertSame("factories should be same", a, b);
33
34 assertTrue("wrong toString", a.toString().contains("foo"));
35 Thread t = a.newThread(() -> TestTools.print("yo"));
36 assertSame("wrong group", a.threadGroup(), t.getThreadGroup());
37 }
38
39 @Test
40 public void hierarchical() {
41 GroupedThreadFactory a = GroupedThreadFactory.groupedThreadFactory("foo/bar");
42 GroupedThreadFactory b = GroupedThreadFactory.groupedThreadFactory("foo/goo");
43 GroupedThreadFactory p = GroupedThreadFactory.groupedThreadFactory("foo");
44
45 assertSame("groups should be same", p.threadGroup(), a.threadGroup().getParent());
46 assertSame("groups should be same", p.threadGroup(), b.threadGroup().getParent());
47
48 assertEquals("wrong name", "foo/bar", a.threadGroup().getName());
49 assertEquals("wrong name", "foo/goo", b.threadGroup().getName());
50 assertEquals("wrong name", "foo", p.threadGroup().getName());
51 }
52
53}