Skip to content

Commit 59cc7dc

Browse files
committed
Add support JDG8+ container
1 parent 272603d commit 59cc7dc

File tree

9 files changed

+317
-0
lines changed

9 files changed

+317
-0
lines changed

containers/jdg/Readme.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Wildfly
2+
3+
- homepage: https://www.redhat.com/it/technologies/jboss-middleware/data-grid
4+
5+
## Usage
6+
```java
7+
final JdgConfiguration conf = JdgConfiguration.builder().httpPort(11222).build();
8+
9+
try (Container cont = new JdgContainer<>(conf)) {
10+
cont.start()
11+
}
12+
```
13+
14+
## Compatibility
15+
- Jdg 8+

containers/jdg/pom.xml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<artifactId>containers-parent</artifactId>
8+
<groupId>org.jboss.qa.jcontainer.containers</groupId>
9+
<version>1.3.2-SNAPSHOT</version>
10+
</parent>
11+
<artifactId>jdg</artifactId>
12+
<name>JContainer Manager :: Containers :: JDG</name>
13+
<properties>
14+
<version.wildfly>2.0.5.Final</version.wildfly>
15+
<version.creaper>1.1.0</version.creaper>
16+
</properties>
17+
<dependencyManagement>
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.infinispan</groupId>
21+
<artifactId>infinispan-bom</artifactId>
22+
<version>12.1.0.CR2</version>
23+
<type>pom</type>
24+
<scope>import</scope>
25+
</dependency>
26+
</dependencies>
27+
</dependencyManagement>
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.slf4j</groupId>
31+
<artifactId>slf4j-log4j12</artifactId>
32+
<version>${version.slf4j}</version>
33+
<scope>test</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.infinispan</groupId>
37+
<artifactId>infinispan-client-hotrod</artifactId>
38+
</dependency>
39+
</dependencies>
40+
<build>
41+
<plugins>
42+
<plugin>
43+
<artifactId>maven-jar-plugin</artifactId>
44+
<executions>
45+
<execution>
46+
<goals>
47+
<goal>test-jar</goal>
48+
</goals>
49+
</execution>
50+
</executions>
51+
</plugin>
52+
</plugins>
53+
</build>
54+
</project>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.jboss.qa.jcontainer.jdg;
2+
3+
import org.jboss.qa.jcontainer.Client;
4+
5+
import java.io.IOException;
6+
import java.util.List;
7+
8+
public class JdgClient<T extends JdgConfiguration> extends Client<T> {
9+
private static final String ERROR_MSG = "JDG container does not support client";
10+
11+
public JdgClient(T configuration) {
12+
super(configuration);
13+
}
14+
15+
@Override
16+
public boolean isConnected() {
17+
return false;
18+
}
19+
20+
@Override
21+
protected void connectInternal() throws Exception {
22+
throw new UnsupportedOperationException(ERROR_MSG);
23+
}
24+
25+
@Override
26+
protected void executeInternal(String command) throws Exception {
27+
throw new UnsupportedOperationException(ERROR_MSG);
28+
}
29+
30+
@Override
31+
protected void executeInternal(List<String> commands) throws Exception {
32+
throw new UnsupportedOperationException(ERROR_MSG);
33+
}
34+
35+
@Override
36+
protected void closeInternal() throws IOException {
37+
throw new UnsupportedOperationException(ERROR_MSG);
38+
}
39+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright 2015 Red Hat Inc. and/or its affiliates and other contributors.
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+
*/
16+
package org.jboss.qa.jcontainer.jdg;
17+
18+
import org.apache.commons.lang3.SystemUtils;
19+
20+
import org.jboss.qa.jcontainer.JavaConfiguration;
21+
22+
import java.io.File;
23+
import java.util.ArrayList;
24+
import java.util.List;
25+
26+
import lombok.Getter;
27+
28+
public class JdgConfiguration extends JavaConfiguration {
29+
30+
public static final int DEFAULT_HTTP_PORT = 11222;
31+
private static final String START_COMMAND = "server";
32+
33+
@Getter
34+
protected final int httpPort;
35+
36+
public JdgConfiguration(Builder<?> builder) {
37+
super(builder);
38+
httpPort = builder.httpPort;
39+
}
40+
41+
public static Builder<?> builder() {
42+
return new Builder2();
43+
}
44+
45+
@Override
46+
public int getBusyPort() {
47+
return httpPort;
48+
}
49+
50+
@Override
51+
public List<String> generateCommand() {
52+
final List<String> cmd = new ArrayList<>();
53+
if (SystemUtils.IS_OS_WINDOWS) {
54+
cmd.add("cmd");
55+
cmd.add("/c");
56+
cmd.add(new File(directory, "bin" + File.separator + START_COMMAND + ".bat").getAbsolutePath());
57+
} else {
58+
cmd.add("bash");
59+
cmd.add(new File(directory, "bin" + File.separator + START_COMMAND + ".sh").getAbsolutePath());
60+
}
61+
return cmd;
62+
}
63+
64+
public File getConfigurationFolder() {
65+
return new File(directory, "server" + File.separator + "conf");
66+
}
67+
68+
public abstract static class Builder<T extends Builder<T>> extends JavaConfiguration.Builder<T> {
69+
70+
protected int httpPort;
71+
72+
public Builder() {
73+
super();
74+
httpPort(DEFAULT_HTTP_PORT);
75+
password("");
76+
logFileName("server.log");
77+
}
78+
79+
public T httpPort(int httpPort) {
80+
this.httpPort = httpPort;
81+
return self();
82+
}
83+
84+
public JdgConfiguration build() {
85+
return new JdgConfiguration(this);
86+
}
87+
}
88+
89+
private static class Builder2 extends Builder<Builder2> {
90+
@Override
91+
protected Builder2 self() {
92+
return this;
93+
}
94+
}
95+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.jboss.qa.jcontainer.jdg;
2+
3+
import org.apache.commons.codec.digest.DigestUtils;
4+
import org.apache.commons.configuration.PropertiesConfiguration;
5+
import org.apache.commons.lang3.StringUtils;
6+
7+
import org.jboss.qa.jcontainer.AbstractContainer;
8+
9+
import java.io.File;
10+
11+
public class JdgContainer<T extends JdgConfiguration, U extends JdgClient<T>, V extends JdgUser>
12+
extends AbstractContainer<T, U, V> {
13+
public JdgContainer(T configuration) {
14+
super(configuration);
15+
}
16+
17+
@Override
18+
protected String getBasicCommand() {
19+
return null;
20+
}
21+
22+
@Override
23+
protected File getLogDirInternal() {
24+
return new File(configuration.getDirectory(), "server" + File.separator + "log");
25+
}
26+
27+
@Override
28+
public void addUser(V user) throws Exception {
29+
final File usersFile = new File(configuration.getConfigurationFolder(), "users.properties");
30+
final File rolesFile = new File(configuration.getConfigurationFolder(), "groups.properties");
31+
final PropertiesConfiguration propConfUsers = new PropertiesConfiguration(usersFile);
32+
propConfUsers.setProperty(user.getUsername(), user.getPassword());
33+
propConfUsers.save();
34+
35+
final PropertiesConfiguration propConfRoles = new PropertiesConfiguration(rolesFile);
36+
propConfRoles.setProperty(user.getUsername(), StringUtils.join(user.getRoles(), ","));
37+
propConfRoles.save();
38+
}
39+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.jboss.qa.jcontainer.jdg;
2+
3+
import org.jboss.qa.jcontainer.User;
4+
5+
public class JdgUser extends User {
6+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.jboss.qa.jcontainer.jdg.test;
2+
3+
import org.jboss.qa.jcontainer.AbstractContainer;
4+
import org.jboss.qa.jcontainer.jdg.JdgConfiguration;
5+
import org.jboss.qa.jcontainer.jdg.JdgContainer;
6+
import org.jboss.qa.jcontainer.jdg.JdgUser;
7+
import org.jboss.qa.jcontainer.test.ContainerTest;
8+
import org.jboss.qa.jcontainer.util.FileUtils;
9+
10+
import org.junit.AfterClass;
11+
import org.junit.Assert;
12+
import org.junit.BeforeClass;
13+
import org.junit.Test;
14+
import org.junit.runner.RunWith;
15+
import org.junit.runners.JUnit4;
16+
17+
import lombok.extern.slf4j.Slf4j;
18+
19+
@Slf4j
20+
@RunWith(JUnit4.class)
21+
public class JdgContainerTest extends ContainerTest {
22+
public static final String JDG_HOME = "/home/federico/Downloads/redhat-datagrid-8.2.0-server"; //getProperty("jdg.home");
23+
protected static AbstractContainer container;
24+
25+
@BeforeClass
26+
public static void beforeClass() throws Exception {
27+
final JdgConfiguration conf = JdgConfiguration.builder().directory(JDG_HOME).build();
28+
container = new JdgContainer(conf);
29+
final JdgUser user = new JdgUser();
30+
user.setUsername("infinispanUsername");
31+
user.setPassword("infinispanPassword");
32+
user.addRoles("admin", "dev");
33+
container.addUser(user);
34+
container.start();
35+
36+
System.out.println(container.isClientSupported());
37+
}
38+
39+
@AfterClass
40+
public static void afterClass() throws Exception {
41+
if (container != null) {
42+
container.stop();
43+
}
44+
}
45+
46+
@Test
47+
public void baseTest() throws Exception {
48+
Assert.assertTrue(container.isRunning());
49+
}
50+
51+
@Test
52+
public void defaultLogFileTest() throws Exception {
53+
Assert.assertTrue(container.getDefaultLogFile().exists());
54+
log.debug("File '{}' - length = {}", container.getDefaultLogFile().getName(), container.getDefaultLogFile().length());
55+
Assert.assertFalse(FileUtils.isEmpty(container.getDefaultLogFile()));
56+
}
57+
58+
@Test
59+
public void stdoutLogFileTest() throws Exception {
60+
Assert.assertTrue(container.getStdoutLogFile().exists());
61+
log.debug("File '{}' - length = {}", container.getStdoutLogFile().getName(), container.getStdoutLogFile().length());
62+
Assert.assertFalse(FileUtils.isEmpty(container.getStdoutLogFile()));
63+
}
64+
}

containers/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<module>wildfly</module>
1717
<module>eap</module>
1818
<module>tomcat</module>
19+
<module>jdg</module>
1920
</modules>
2021
<dependencies>
2122
<dependency>

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@
188188
<name>fuse.home</name>
189189
<value>${fuse.home}</value>
190190
</property>
191+
<property>
192+
<name>jdg.home</name>
193+
<value>${jdg.home}</value>
194+
</property>
191195
</systemProperties>
192196
</configuration>
193197
</plugin>

0 commit comments

Comments
 (0)