blob: 0f20ccb8f9b73d34ed3c705c238d8eeffc625200 (
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.standalone;
public class StandAloneClusterControllerTest extends ClusterControllerTest {
abstract class Runner implements Runnable {
boolean completed = false;
Exception exception = null;
public void run() {
try{
attemptRun();
completed = true;
} catch (Exception e) {
exception = e;
}
}
public abstract void attemptRun() throws Exception;
}
public void testSimpleStartStop() throws Exception {
setupConfig();
ClusterControllerConfigFetcher configFetcher = new ClusterControllerConfigFetcher();
StandAloneClusterController controller = new StandAloneClusterController(configFetcher);
assertEquals("Fleetcontroller 0 of cluster storage", controller.getName());
controller.start();
controller.stop();
}
public void testShortRun() throws Exception {
setupConfig();
ClusterControllerConfigFetcher configFetcher = new ClusterControllerConfigFetcher() {
int counter = 0;
@Override
public boolean updated(long timeoutMillis) throws Exception {
return (++counter % 2 == 0);
}
@Override
public void close() {
throw new RuntimeException("Failed to stop");
}
};
final StandAloneClusterController controller = new StandAloneClusterController(configFetcher);
assertEquals("Fleetcontroller 0 of cluster storage", controller.getName());
controller.start();
Runner r = new Runner() {
@Override
public void attemptRun() throws Exception {
controller.run();
}
};
Thread t = new Thread(r);
t.start();
for (int i=0; i<100; ++i) {
try{ Thread.sleep(1); } catch (InterruptedException e) {}
synchronized (controller) {
controller.notifyAll();
}
}
StandAloneClusterController.ShutdownHook hook = new StandAloneClusterController.ShutdownHook(controller);
hook.start();
hook.join();
t.join();
assertEquals(true, r.completed);
assertNull(r.exception);
}
public void testFailStart() throws Exception {
setupConfig();
ClusterControllerConfigFetcher configFetcher = new ClusterControllerConfigFetcher();
StandAloneClusterController controller = new StandAloneClusterController(configFetcher) {
@Override
public void start() throws Exception {
throw new RuntimeException("Foo");
}
};
StandAloneClusterController.runApplication(controller);
}
public void testFailRun() throws Exception {
setupConfig();
ClusterControllerConfigFetcher configFetcher = new ClusterControllerConfigFetcher();
StandAloneClusterController controller = new StandAloneClusterController(configFetcher) {
@Override
public void run() throws Exception {
throw new RuntimeException("Foo");
}
};
StandAloneClusterController.runApplication(controller);
}
public void testCallMainToGetCoverage() throws Exception {
tearDown();
setProperty("config.id", "file:non-existing");
try{
StandAloneClusterController.main(new String[0]);
fail("Control should not get here");
} catch (IllegalArgumentException e) {
}
}
}
|