blob: e3793ee305718e97dff365289c09c10cae220c16 (
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
47
48
49
50
51
52
53
54
55
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.logserver;
import com.yahoo.log.LogSetup;
import com.yahoo.logserver.handlers.LogHandler;
import com.yahoo.logserver.handlers.logmetrics.LogMetricsPlugin;
import com.yahoo.logserver.test.LogDispatcherTestCase;
import org.junit.Test;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* Unit tests for the Server class.
*
* @author Bjorn Borud
*/
public class ServerTestCase {
@Test
public void testStartupAndRegHandlers() throws IOException, InterruptedException {
Server.help();
Server server = Server.getInstance();
server.initialize(18322, 18323); // TODO Stop using hardcoded ports
LogSetup.clearHandlers();
Thread serverThread = new Thread(server);
serverThread.start();
assertTrue(serverThread.isAlive());
LogHandler handler = new LogDispatcherTestCase.MockHandler();
server.registerLogHandler(handler, "foo");
assertEquals(Server.threadNameForHandler().get(handler), "foo");
server.unregisterLogHandler(handler);
assertEquals(Server.threadNameForHandler().get(handler), null);
serverThread.interrupt();
try {
serverThread.join();
assertTrue(true);
} catch (InterruptedException e) {
fail();
}
}
@Test
public void testPluginLoaderClassLoading() {
AbstractPluginLoader loader = new BuiltinPluginLoader();
System.setProperty("logserver.logmetrics.enable", "false");
loader.loadFromClass(LogMetricsPlugin.class);
System.setProperty("logserver.logmetrics.enable", "true");
loader.loadFromClass(LogMetricsPlugin.class); // Hm, no way to verify it was loaded
}
}
|