forked from wildfly/wildfly-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ManagedServerBootCmdFactoryTestCase.java
159 lines (145 loc) · 6.69 KB
/
ManagedServerBootCmdFactoryTestCase.java
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* Copyright 2017 JBoss by Red Hat.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.host.controller;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.jboss.as.host.controller.HostControllerEnvironment.HOME_DIR;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hamcrest.MatcherAssert;
import org.jboss.as.controller.ExpressionResolver;
import org.jboss.as.controller.RunningMode;
import org.jboss.dmr.ModelNode;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
/**
*
* @author Emmanuel Hugonnet (c) 2017 Red Hat, inc.
*/
public class ManagedServerBootCmdFactoryTestCase {
private static final Path homeDir = new File(System.getProperty("basedir", ".")).toPath().resolve("target").resolve("wildlfy");
private static final Path domainDir = homeDir.resolve("domain");
private static final Path configurationDir = domainDir.resolve("configuration");
@BeforeClass
public static void createHomeDir() throws IOException {
Files.createDirectories(configurationDir);
}
@AfterClass
public static void clean() throws IOException {
if (Files.exists(homeDir)) {
Files.walkFileTree(homeDir, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}
});
}
}
private static HostControllerEnvironment getTestHostEnvironment() throws UnknownHostException {
Map<String, String> hostSystemProperties = new HashMap<>();
hostSystemProperties.put("jboss.server.log.dir", "/tmp/");
hostSystemProperties.put("jboss.domain.log.dir", "/tmp/");
hostSystemProperties.put("jboss.server.temp.dir", "/tmp/");
hostSystemProperties.put(HOME_DIR, homeDir.toAbsolutePath().toString());
return new HostControllerEnvironment(
hostSystemProperties, false, "/opt/wildfly/modules",
InetAddress.getLocalHost(), 8080, InetAddress.getLocalHost(), 9990, null, null, null, null, null,
RunningMode.NORMAL, true, true, null);
}
private static ModelNode getHostModel() {
ModelNode hostModel = new ModelNode();
ModelNode serverModel = new ModelNode();
serverModel.get("group").set("test-group");
final ModelNode jvm = serverModel.get("jvm", "test-jvm");
jvm.get("heap-size").set("64m");
jvm.get("max-heap-size").set("256m");
jvm.get("module-options").setEmptyList().add("-javaagent:test-agent.jar");
hostModel.get("server-config").get("test-server").set(serverModel);
return hostModel;
}
private static ModelNode getDomainModel() {
ModelNode domainModel = new ModelNode();
domainModel.get("server-group").get("test-group").setEmptyObject();
return domainModel;
}
/**
* Test of createConfiguration method, of class ManagedServerBootCmdFactory.
*/
@Test
public void testCreateConfiguration() throws UnknownHostException {
System.out.println("createConfiguration");
ManagedServerBootCmdFactory instance = new ManagedServerBootCmdFactory("test-server", getDomainModel(), getHostModel(), getTestHostEnvironment(), ExpressionResolver.TEST_RESOLVER, false);
ManagedServerBootConfiguration result = instance.createConfiguration();
Assert.assertNotNull(result);
}
/**
* Test of getServerLaunchCommand method, of class
* ManagedServerBootCmdFactory.
*/
@Test
public void testGetServerLaunchCommand() throws UnknownHostException {
System.out.println("getServerLaunchCommand");
ManagedServerBootCmdFactory instance = new ManagedServerBootCmdFactory("test-server", getDomainModel(), getHostModel(), getTestHostEnvironment(), ExpressionResolver.TEST_RESOLVER, false);
List<String> result = instance.getServerLaunchCommand();
MatcherAssert.assertThat(result.size(), is(notNullValue()));
if (result.size() > 18) {
MatcherAssert.assertThat(result.size(), is(32));
} else {
MatcherAssert.assertThat(result.size(), is(18));
}
Assert.assertTrue("Missing -javaagent:test-agent.jar entry: " + result, result.contains("-javaagent:test-agent.jar"));
boolean sawDServer = false;
boolean sawDpcid = false;
boolean sawJbmAgent = false;
for (String arg : result) {
if (arg.startsWith("-Djboss.server.log.dir")) {
MatcherAssert.assertThat(arg, is(not("-Djboss.server.log.dir=/tmp/")));
} else if (arg.startsWith("-Djboss.server.temp.dir")) {
MatcherAssert.assertThat(arg, is(not("-Djboss.server.temp.dir=/tmp/")));
} else if (arg.startsWith("-Djboss.domain.log.dir")) {
MatcherAssert.assertThat(arg, is("-Djboss.domain.log.dir=/tmp/"));
} else if (arg.equals("-D[" + ManagedServer.getServerProcessName("test-server") + "]")) {
sawDServer = true;
} else if (arg.startsWith("-D[pcid:") && arg.endsWith("]")) {
sawDpcid = true;
} else if (arg.startsWith("-javaagent:") && arg.endsWith("jboss-modules.jar")) {
sawJbmAgent = true;
}
}
Assert.assertTrue(sawDServer);
Assert.assertTrue(sawDpcid);
Assert.assertTrue("Missing jboss-modules.jar configured as an agent: " + result, sawJbmAgent);
}
}