Skip to content

Commit

Permalink
AS7-2448 TS: use Logger; fix certain System.out-s not being seen anyw…
Browse files Browse the repository at this point in the history
…here
  • Loading branch information
rhusar committed Mar 13, 2013
1 parent be64e2d commit 1fb8ba8
Show file tree
Hide file tree
Showing 18 changed files with 76 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.jboss.arquillian.container.test.api.ContainerController;
import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.logging.Logger;

/**
* Utility class to start and stop containers and/or deployments.
Expand All @@ -37,81 +38,83 @@
*/
public final class NodeUtil {

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

public static void deploy(Deployer deployer, String... deployments) {
for (int i = 0; i < deployments.length; i++) {
System.out.println(new Date() + " deploying deployment=" + deployments[i]);
log.info("Deploying deployment=" + deployments[i]);
deployer.deploy(deployments[i]);
}
}

public static void undeploy(Deployer deployer, String... deployments) {
for (int i = 0; i < deployments.length; i++) {
System.out.println(new Date() + " undeploying deployment=" + deployments[i]);
log.info("Undeploying deployment=" + deployments[i]);
deployer.undeploy(deployments[i]);
}
}

public static void start(ContainerController controller, Deployer deployer, String container, String deployment) {
try {
System.out.println(new Date() + "starting deployment=" + deployment + ", container=" + container);
log.info("Starting deployment=" + deployment + ", container=" + container);
controller.start(container);
deployer.deploy(deployment);
System.out.println(new Date() + "started deployment=" + deployment + ", container=" + container);
log.info("Started deployment=" + deployment + ", container=" + container);
} catch (Throwable e) {
e.printStackTrace(System.err);
log.error(e);
}
}

public static void start(ContainerController controller, String[] containers) {
// TODO do this in parallel.
for (int i = 0; i < containers.length; i++) {
try {
System.out.println(new Date() + "starting deployment=NONE, container=" + containers[i]);
log.info("Starting deployment=NONE, container=" + containers[i]);
controller.start(containers[i]);
} catch (Throwable e) {
e.printStackTrace(System.err);
log.error(e);
}
}
}

public static void start(ContainerController controller, String container) {
try {
System.out.println(new Date() + "starting deployment=NONE, container=" + container);
log.info("Starting deployment=NONE, container=" + container);
controller.start(container);
} catch (Throwable e) {
e.printStackTrace(System.err);
log.error(e);
}
}

public static void stop(ContainerController controller, String[] containers) {
for (int i = 0; i < containers.length; i++) {
try {
System.out.println(new Date() + "stopping container=" + containers[i]);
log.info("Stopping container=" + containers[i]);
controller.stop(containers[i]);
System.out.println(new Date() + "stopped container=" + containers[i]);
log.info("Stopped container=" + containers[i]);
} catch (Throwable e) {
e.printStackTrace(System.err);
log.error(e);
}
}
}

public static void stop(ContainerController controller, Deployer deployer, String container, String deployment) {
try {
System.out.println(new Date() + "stopping deployment=" + deployment + ", container=" + container);
log.info("Stopping deployment=" + deployment + ", container=" + container);
deployer.undeploy(deployment);
controller.stop(container);
System.out.println(new Date() + "stopped deployment=" + deployment + ", container=" + container);
log.info("Stopped deployment=" + deployment + ", container=" + container);
} catch (Throwable e) {
e.printStackTrace(System.err);
log.error(e);
}
}

public static void stop(ContainerController controller, String container) {
try {
controller.stop(container);
System.out.println(new Date() + "stopped deployment=NONE, container=" + container);
log.info("Stopped deployment=NONE, container=" + container);
} catch (Throwable e) {
e.printStackTrace(System.err);
log.error(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.test.clustering.ClusteringTestConstants;
import org.jboss.as.test.clustering.NodeUtil;
import org.jboss.logging.Logger;
import org.junit.BeforeClass;
import org.junit.Test;

Expand All @@ -41,6 +42,8 @@
*/
public abstract class ClusterAbstractTestCase implements ClusteringTestConstants {

protected static final Logger log = Logger.getLogger(ClusterAbstractTestCase.class);

@ArquillianResource
protected ContainerController controller;
@ArquillianResource
Expand Down Expand Up @@ -102,7 +105,7 @@ protected void undeploy(String[] deployments) {
public static void printSystemProperties() {
// Enable for debugging if you like:
//Properties systemProperties = System.getProperties();
//System.out.println("System properties:\n" + systemProperties);
//log.info("System properties:\n" + systemProperties);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private static WebArchive createDeployment() {
"</beans>"), "beans.xml");
war.addClasses(ViewChangeListener.class, ViewChangeListenerBean.class, ViewChangeListenerServlet.class);
war.setManifest(new StringAsset("Manifest-Version: 1.0\nDependencies: org.jboss.msc, org.jboss.as.clustering.common, org.infinispan\n"));
System.out.println(war.toString(true));
log.info(war.toString(true));
return war;
}

Expand All @@ -118,7 +118,7 @@ public void testRestart(
String url1 = baseURL1.toString() + "count";
String url2 = baseURL2.toString() + "count";

System.out.println("URLs are: " + url1 + ", " + url2);
log.info("URLs are: " + url1 + ", " + url2);

try {
this.establishView(client, baseURL1, NODE_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ private void validateBalancing(Stateless bean, int numCalls, int expectedServers
int frequency = Collections.frequency(results, entry);
Assert.assertTrue(Integer.toString(frequency), frequency >= minCalls);
}
System.out.println(String.format("All %d servers processed at least %f of calls", expectedServers, minCalls));
log.info(String.format("All %d servers processed at least %f of calls", expectedServers, minCalls));
}

private void establishView(ViewChangeListener listener, String... members) throws InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private static Archive<?> createDeployment() {
war.addAsResource(new StringAsset(persistence_xml), "META-INF/persistence.xml");
war.addClasses(ViewChangeListener.class, ViewChangeListenerBean.class, ViewChangeListenerServlet.class);
war.setManifest(new StringAsset("Manifest-Version: 1.0\nDependencies: org.jboss.msc, org.jboss.as.clustering.common, org.infinispan\n"));
System.out.println(war.toString(true));
log.info(war.toString(true));
return war;
}

Expand Down Expand Up @@ -163,7 +163,7 @@ public void testSecondLevelCache(

String employeeName = executeUrlWithAnswer(client, xpc1_create_url, "create entity in node1 in memory db"); //
assertEquals(employeeName, "Tom Brady");
System.out.println(new Date() + "about to read entity on node1 (from xpc queue)");
log.info(new Date() + "about to read entity on node1 (from xpc queue)");

employeeName = executeUrlWithAnswer(client, xpc1_get_url, "on node1, node1 should be able to read entity on node1");
assertEquals(employeeName, "Tom Brady");
Expand Down Expand Up @@ -231,11 +231,11 @@ public void testBasicXPC(
try {
// extended persistence context is available on node1

System.out.println(new Date() + "create employee entity ");
log.info(new Date() + "create employee entity ");
String employeeName = executeUrlWithAnswer(client, xpc1_create_url, "create entity that lives in the extended persistence context that this test will verify is always available");
assertEquals(employeeName, "Tom Brady");

System.out.println(new Date() + "1. about to read entity on node1");
log.info(new Date() + "1. about to read entity on node1");
// ensure that we can get it from node 1
employeeName = executeUrlWithAnswer(client, xpc1_get_url, "1. xpc on node1, node1 should be able to read entity on node1");
assertEquals(employeeName, "Tom Brady");
Expand All @@ -244,7 +244,7 @@ public void testBasicXPC(

start(CONTAINER_2);

System.out.println(new Date() + "2. started node2 + deployed, about to read entity on node1");
log.info(new Date() + "2. started node2 + deployed, about to read entity on node1");

employeeName = executeUrlWithAnswer(client, xpc2_get_url, "2. started node2, xpc on node1, node1 should be able to read entity on node1");
assertEquals(employeeName, "Tom Brady");
Expand All @@ -254,7 +254,7 @@ public void testBasicXPC(
// failover to deployment2
stop(CONTAINER_1); // failover #1 to node 2

System.out.println(new Date() + "3. stopped node1 to force failover, about to read entity on node2");
log.info(new Date() + "3. stopped node1 to force failover, about to read entity on node2");

employeeName = executeUrlWithAnswer(client, xpc2_get_url, "3. stopped deployment on node1, xpc should failover to node2, node2 should be able to read entity from xpc");
assertEquals(employeeName, "Tom Brady");
Expand All @@ -263,7 +263,7 @@ public void testBasicXPC(

String destroyed = executeUrlWithAnswer(client, xpc2_getdestroy_url, "4. destroy the bean on node2");
assertEquals(destroyed, "destroy");
System.out.println(new Date() + "4. test is done");
log.info(new Date() + "4. test is done");

} finally {
client.getConnectionManager().shutdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.hibernate.Session;
import org.hibernate.stat.SecondLevelCacheStatistics;
import org.jboss.ejb3.annotation.Clustered;
import org.jboss.logging.Logger;

import java.sql.Connection;
import java.util.HashMap;
Expand All @@ -47,6 +48,8 @@

public class StatefulBean implements Stateful {

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

@PersistenceContext(unitName = "mypc", type = PersistenceContextType.EXTENDED)
EntityManager em;

Expand Down Expand Up @@ -132,9 +135,9 @@ public void clear() {
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
@Override
public void echo(String message) {
System.out.println("echo entered for " + message);
log.info("echo entered for " + message);
logStats("echo " + message);
System.out.println("echo completed for " + message);
log.info("echo completed for " + message);
}


Expand Down Expand Up @@ -166,14 +169,14 @@ public long getEmployeesInMemory() {

private void logStats(String methodName) {
Session session = em.unwrap(Session.class);
System.out.println(methodName + "(version="+version+", HashMap version="+valueBag.get("version")+") logging statistics for session = " + session);
log.info(methodName + "(version="+version+", HashMap version="+valueBag.get("version")+") logging statistics for session = " + session);
session.getSessionFactory().getStatistics().setStatisticsEnabled(true);
session.getSessionFactory().getStatistics().logSummary();
String entityRegionNames[] = session.getSessionFactory().getStatistics().getSecondLevelCacheRegionNames();
for (String name: entityRegionNames) {
System.out.println("cache entity region name = " + name);
log.info("cache entity region name = " + name);
SecondLevelCacheStatistics stats = session.getSessionFactory().getStatistics().getSecondLevelCacheStatistics(name);
System.out.println("2lc for " + name+ ": " + stats.toString());
log.info("2lc for " + name+ ": " + stats.toString());

}
// we will want to return the SecondLevelCacheStatistics for Employee
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import static org.junit.Assert.assertTrue;

import org.jboss.as.test.clustering.LocalEJBDirectory;
import org.jboss.logging.Logger;

/**
* @author Paul Ferraro
Expand All @@ -47,6 +48,8 @@
public class StatefulServlet extends HttpServlet {
private static final long serialVersionUID = -592774116315946908L;

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

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
HttpSession session = req.getSession(true);
Expand All @@ -60,7 +63,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
}

String command = req.getParameter("command");
System.out.println(StatefulServlet.class.getName() + ": command = " + command);
log.info(StatefulServlet.class.getName() + ": command = " + command);
String answer = null;

if("createEmployee".equals(command)) {
Expand Down Expand Up @@ -118,6 +121,6 @@ else if("deleteEmployeeViaJDBC".equals(command)) {
}
resp.getWriter().write("Success");
session.setAttribute("bean", bean);
System.out.println(StatefulServlet.class.getName() + ": command = " + command + " finished");
log.info(StatefulServlet.class.getName() + ": command = " + command + " finished");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public void testGracefulSimpleFailover(
String url1 = baseURL1.toString() + "home.jsf";
String url2 = baseURL2.toString() + "home.jsf";

System.out.println("URLs are: " + url1 + ", " + url2);
log.info("URLs are: " + url1 + ", " + url2);

try {
HttpResponse response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public void testSingletonService(
URI defaultURI1 = MyServiceServlet.createURI(baseURL1, MyService.DEFAULT_SERVICE_NAME);
URI defaultURI2 = MyServiceServlet.createURI(baseURL2, MyService.DEFAULT_SERVICE_NAME);

log.info("URLs are: " + defaultURI1 + ", " + defaultURI2);

URI quorumURI1 = MyServiceServlet.createURI(baseURL1, MyService.QUORUM_SERVICE_NAME);
URI quorumURI2 = MyServiceServlet.createURI(baseURL2, MyService.QUORUM_SERVICE_NAME);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.jboss.as.server.ServerEnvironmentService;
import org.jboss.msc.service.ServiceActivator;
import org.jboss.msc.service.ServiceActivatorContext;
import org.jboss.logging.Logger;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.value.InjectedValue;
Expand All @@ -41,6 +42,8 @@
*/
public class MyServiceActivator implements ServiceActivator {

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

public static final String PREFERRED_NODE = NODE_2;

@Override
Expand Down
Loading

0 comments on commit 1fb8ba8

Please sign in to comment.