-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathClassLevelAppContextFixture.java
More file actions
62 lines (52 loc) · 1.44 KB
/
ClassLevelAppContextFixture.java
File metadata and controls
62 lines (52 loc) · 1.44 KB
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
package org.tron.common;
import io.grpc.ManagedChannel;
import java.util.concurrent.TimeUnit;
import org.tron.common.application.ApplicationFactory;
import org.tron.common.application.TronApplicationContext;
import org.tron.core.config.DefaultConfig;
/**
* Shared class-level fixture for tests that manually manage a TronApplicationContext.
*/
public class ClassLevelAppContextFixture {
private TronApplicationContext context;
public TronApplicationContext createContext() {
context = new TronApplicationContext(DefaultConfig.class);
return context;
}
public TronApplicationContext createAndStart() {
createContext();
startApp();
return context;
}
public void startApp() {
ApplicationFactory.create(context).startup();
}
public TronApplicationContext getContext() {
return context;
}
public void close() {
if (context != null) {
context.close();
context = null;
}
}
public static void shutdownChannel(ManagedChannel channel) {
if (channel == null) {
return;
}
try {
channel.shutdown();
if (!channel.awaitTermination(5, TimeUnit.SECONDS)) {
channel.shutdownNow();
}
} catch (InterruptedException e) {
channel.shutdownNow();
Thread.currentThread().interrupt();
}
}
public static void shutdownChannels(ManagedChannel... channels) {
for (ManagedChannel channel : channels) {
shutdownChannel(channel);
}
}
}