Skip to content

Commit

Permalink
Testing rest on cluster + fixes for JMS to run on cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
mhajas committed Jun 13, 2018
1 parent c36b8a9 commit 74ff3ae
Show file tree
Hide file tree
Showing 11 changed files with 903 additions and 46 deletions.
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,38 @@
- Run command:
````
cd $JBOSS_HOME/bin
./jboss-cli.sh --file=adapter-install-offline.cli -Dserver.config=standalone-full.xml
./jboss-cli.sh --file=adapter-install-offline.cli -Dserver.config=standalone-full-ha.xml
````

if you are using older version of keycloak adapter -Dserver.config property won't work so you need to specify standalone-full.xml within cli file

##### Add jms-queue inside standalone-full.xml
##### Add jms-topic inside standalone-full-ha.xml

````
<jms-queue name="ChangedParsersQueue" entries="java:jboss/exported/jms/queue/ChangedParsersQueue"/>
<jms-topic name="ChangedParsersTopic" entries="java:jboss/exported/jms/topic/ChangedParsersTopic"/>
````

+ Change default password from CHANGE ME!! to something else in acivemq subsystem in <cluster element

#### Datasource used for testing

````
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:/tmp/ParserManager;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
````

#### Run wildfly

````
standalone.sh -c standalone-full.xml
./standalone.sh -c standalone-full-ha.xml
````

#### Deploy project:
Expand Down
45 changes: 42 additions & 3 deletions rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.0.2</version>
<scope>provided</scope>
<version>2.9.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.5</version>
</dependency>
<dependency>
<groupId>jboss</groupId>
Expand Down Expand Up @@ -126,14 +130,49 @@
<resource>
<directory>${pom.basedir}/src/test/resources</directory>
<includes>
<include>standalone-full.xml</include>
<include>standalone-full-ha.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>1.2.1</version>
<executions>
<execution>
<id>Add base directory 1</id>
<phase>process-test-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>mkdir</executable>
<arguments>
<argument>-p</argument>
<argument>${pom.basedir}/target/wildfly-11.0.0.Final/standalone-ha-node-1/deployments</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>Add base directory 2</id>
<phase>process-test-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>mkdir</executable>
<arguments>
<argument>-p</argument>
<argument>${pom.basedir}/target/wildfly-11.0.0.Final/standalone-ha-node-2/deployments</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
@Named
@MessageDriven(name = "ParserConfigurationHandler",
activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "java:jboss/exported/jms/queue/ChangedParsersQueue"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "java:jboss/exported/jms/topic/ChangedParsersTopic"),
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")
/*mappedName = "jms/myQueue"*/})
public class ParserConfigurationMDB implements MessageListener {
Expand Down
142 changes: 142 additions & 0 deletions rest/src/test/java/cz.fi.muni.pv243.rest/ClusterParserServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package cz.fi.muni.pv243.rest;

import cz.fi.muni.pv243.entity.Parser;
import cz.fi.muni.pv243.entity.Restaurant;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.container.test.api.TargetsContainer;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.logging.Logger;

import static cz.fi.muni.pv243.rest.Configuration.BASE_URL2;
import static io.restassured.RestAssured.given;
import static org.hamcrest.core.Is.is;

@RunWith(Arquillian.class)
@RunAsClient
@Ignore // Don't know ho to cleanup server base config after test, removing configuration like in @BeforeClass doesn't work, but tests are working when running only this class
public class ClusterParserServiceTest {

private static final Logger log = Logger.getLogger( ClusterParserServiceTest.class.getName() );

private static final String BASE_URL = Configuration.BASE_URL;

private Parser parser;
private static boolean initialized = false;

@ArquillianResource
private Deployer deployer;

@Deployment
public static WebArchive createDeployment() {
return Configuration.deployment();
}

@Deployment(name = "d2", managed = false)
@TargetsContainer("node-2")
public static WebArchive createDeployment2() {
return Configuration.deployment();
}
//
// @BeforeClass
// public static void removeContainerConfig() throws IOException {
// FileUtils.deleteDirectory(new File(System.getProperty("jboss.home") + "/standalone-ha-node-1/configuration"));
// FileUtils.deleteDirectory(new File(System.getProperty("jboss.home") + "/standalone-ha-node-2/configuration"));
// }

@Before
public void init(){
if (!initialized) { //workaround, beforeClass have to be static, but store is injected
parser = new Parser();
parser.setXpath("/a/b/c");
Restaurant restaurant = new Restaurant();
restaurant.setGooglePlaceID("testGOOGLEid");
restaurant.setName("uPstrosa");
restaurant.addParser(parser);
parser.setRestaurant(restaurant);
//store.addParser(parser);
initialized = true;
deployer.deploy("d2");
}
}

@Test
@Ignore
public void testCluster(){
Response response = given()
.when()
.accept(ContentType.JSON)
.contentType(ContentType.JSON)
.body(parser)
.post(BASE_URL + "/parsers");
log.info(new Object(){}.getClass().getEnclosingMethod().getName() + "\n" +
response.body().prettyPrint());

response = given()
.when()
.get(BASE_URL + "/parsers");
log.info(new Object(){}.getClass().getEnclosingMethod().getName() + "\n" +
response.body().prettyPrint());

response.then()
.statusCode(200)
.body("find{it.id==1}.xpath", is(parser.getXpath()));

response = given()
.when()
.get(BASE_URL2 + "/parsers");
System.out.println("SECOND CALL ___------------------------");
log.info(new Object(){}.getClass().getEnclosingMethod().getName() + "\n" +
response.body().prettyPrint());

response.then()
.statusCode(200)
.body("find{it.id==1}.xpath", is(parser.getXpath()));
}

// @Test
// public void testPost() throws IOException {
// {
// Parser newParser = new Parser();
// newParser.setXpath("x/y/z");
// Restaurant restaurant = new Restaurant();
// restaurant.setGooglePlaceID("testGOOGLEid");
// restaurant.setName("uPstrosa");
// restaurant.addParser(newParser);
// newParser.setRestaurant(restaurant);
//
// Response response = given()
// .when()
// .accept(ContentType.JSON)
// .contentType(ContentType.JSON)
// .body(newParser)
// .post(BASE_URL + "/parsers");
// log.info(new Object() {
// }.getClass().getEnclosingMethod().getName() + "\n" +
// response.body().prettyPrint());
//
// response.then()
// .statusCode(200)
// .body("xpath", is(newParser.getXpath()));
// assertThat(store.getAllParsers(false))
// .hasSize(2);
// }
//
// Response response = given()
// .when()
// .accept(ContentType.JSON)
// .contentType(ContentType.JSON)
// .post(BASE_URL + "/parsers");
//
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Configuration {
: 8080 + Integer.valueOf(System.getProperty("port.offset"));

public final static String BASE_URL = "http://localhost:" + PORT + "/" + Configuration.WAR_NAME + "/rest";
public final static String BASE_URL2 = "http://localhost:" + Integer.toString(8080 + 200) + "/" + Configuration.WAR_NAME + "/rest";

public static final String WAR_NAME = "test-rest";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
import cz.fi.muni.pv243.store.ParserStore;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import org.apache.commons.io.FileUtils;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.transaction.api.annotation.TransactionMode;
import org.jboss.arquillian.transaction.api.annotation.Transactional;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;

Expand All @@ -35,7 +36,7 @@ public class ParserServiceTest {

@Inject
@CachedStore
ParserStore store;
private ParserStore store;

@Deployment
public static WebArchive createDeployment() {
Expand Down
74 changes: 53 additions & 21 deletions rest/src/test/resources/arquillian.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,58 @@
xsi:schemaLocation="http://jboss.org/schema/arquillian
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">

<defaultProtocol type="Servlet 3.0" />
<container qualifier="jboss" default="true">
<configuration>
<property name="allowConnectingToRunningServer">true</property>
<property name="jbossHome">${jboss.home}</property>
<property name="serverConfig">standalone-full.xml</property>
<property name="outputToConsole">true</property>

<!-- Test must running on another server after mvn wildfly:deploy -->
<property name="jbossArguments">
-Djboss.socket.binding.port-offset=${port.offset}
</property>
<property name="managementPort">10090</property>

<!-- For debugging e.g. mvn clean test -Dmaven.surefire.debug -->
<property name="javaVmArguments">
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=localhost:5005
-Dport.offset=${port.offset}
</property>
</configuration>
</container>
<defaultProtocol type="Servlet 3.0"/>

<group qualifier="wildfly-cluster" default="true">
<container qualifier="jboss" default="true">
<configuration>
<property name="allowConnectingToRunningServer">true</property>
<property name="jbossHome">${jboss.home}</property>
<property name="serverConfig">standalone-full-ha.xml</property>
<property name="adapterImplClass">org.jboss.as.arquillian.container.managed.ManagedDeployableContainer</property>
<property name="outputToConsole">true</property>
<property name="setupCleanServerBaseDir">false</property>
<property name="cleanServerBaseDir">${jboss.home}/standalone-ha-node-1</property>

<!-- Test must running on another server after mvn wildfly:deploy -->
<property name="jbossArguments">
-Djboss.socket.binding.port-offset=${port.offset}
</property>
<property name="managementPort">10090</property>

<!-- For debugging e.g. mvn clean test -Dmaven.surefire.debug -->
<property name="javaVmArguments">
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=localhost:5006
-Dport.offset=${port.offset}
-Djava.net.preferIPv4Stack=true
</property>
</configuration>
</container>

<container qualifier="node-2">
<configuration>
<property name="allowConnectingToRunningServer">true</property>
<property name="jbossHome">${jboss.home}</property>
<property name="serverConfig">standalone-full-ha.xml</property>
<property name="adapterImplClass">org.jboss.as.arquillian.container.managed.ManagedDeployableContainer</property>
<property name="outputToConsole">true</property>
<property name="setupCleanServerBaseDir">false</property>
<property name="cleanServerBaseDir">${jboss.home}/standalone-ha-node-2</property>

<!-- Test must running on another server after mvn wildfly:deploy -->
<property name="jbossArguments">
-Djboss.socket.binding.port-offset=200
</property>
<property name="managementPort">10190</property>

<!-- For debugging e.g. mvn clean test -Dmaven.surefire.debug -->
<property name="javaVmArguments">
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=localhost:5007
-Dport.offset=200
-Djava.net.preferIPv4Stack=true
</property>
</configuration>
</container>
</group>

</arquillian>
Loading

0 comments on commit 74ff3ae

Please sign in to comment.