You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by wi...@apache.org on 2014/02/27 13:37:54 UTC
[3/3] git commit: MARMOTTA-440: trying to fix test shutdown
MARMOTTA-440: trying to fix test shutdown
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/397cd2af
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/397cd2af
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/397cd2af
Branch: refs/heads/ldp
Commit: 397cd2aff0a611b769eabc74e0941c800a7c4fe0
Parents: 66a7f5b
Author: Sergio Fernández <wi...@apache.org>
Authored: Thu Feb 27 13:37:40 2014 +0100
Committer: Sergio Fernández <wi...@apache.org>
Committed: Thu Feb 27 13:37:40 2014 +0100
----------------------------------------------------------------------
platform/marmotta-core/pom.xml | 5 +
.../core/startup/MarmottaStartupService.java | 114 +++++++++---------
.../core/test/base/AbstractMarmotta.java | 2 +-
.../platform/core/test/base/JettyMarmotta.java | 120 +++++++++----------
.../ldp/webservices/LdpWebServiceTest.java | 3 +-
5 files changed, 125 insertions(+), 119 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/397cd2af/platform/marmotta-core/pom.xml
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/pom.xml b/platform/marmotta-core/pom.xml
index 3c2bb95..5a65046 100644
--- a/platform/marmotta-core/pom.xml
+++ b/platform/marmotta-core/pom.xml
@@ -385,6 +385,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.jboss.weld.servlet</groupId>
+ <artifactId>weld-servlet-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/397cd2af/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/startup/MarmottaStartupService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/startup/MarmottaStartupService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/startup/MarmottaStartupService.java
index f0b4ca5..0036a8b 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/startup/MarmottaStartupService.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/startup/MarmottaStartupService.java
@@ -57,7 +57,7 @@ public class MarmottaStartupService {
private static final String DEFAULT_KIWI_VERSION = "undefined";
- private Logger log = LoggerFactory.getLogger(MarmottaStartupService.class);
+ private Logger log = LoggerFactory.getLogger(MarmottaStartupService.class);
@Inject
private ConfigurationService configurationService;
@@ -65,10 +65,12 @@ public class MarmottaStartupService {
@Inject
private ModuleService moduleService;
- @Inject @Any
+ @Inject
+ @Any
private Event<SystemStartupEvent> startupEvent;
- @Inject @Any
+ @Inject
+ @Any
private Event<SesameStartupEvent> sesameEvent;
private boolean configurationStarted = false;
@@ -88,9 +90,9 @@ public class MarmottaStartupService {
* The parameters lmfHome and configurationOverride can be used to override the default settings
* of the Apache Marmotta.
*
- * @param lmfHome home directory of the Apache Marmotta instance (may be null, in which case the default will be used)
- * @param configurationOverride configuration options that should override the default values from default-config.properties (may be null)
- * @param context the servlet context the Apache Marmotta is running in (may be null)
+ * @param lmfHome home directory of the Apache Marmotta instance (may be null, in which case the default will be used)
+ * @param configurationOverride configuration options that should override the default values from default-config.properties (may be null)
+ * @param context the servlet context the Apache Marmotta is running in (may be null)
*/
public void startupConfiguration(String home, Configuration configurationOverride, ServletContext context) {
lock.lock();
@@ -99,14 +101,14 @@ public class MarmottaStartupService {
String versionNumber = DEFAULT_KIWI_VERSION;
try {
- if(configurationStarted) {
+ if (configurationStarted) {
log.warn("Apache Marmotta Startup: configuration already started; ignoring second request");
return;
}
ModuleConfiguration coreConfiguration = moduleService.getModuleConfiguration(this.getClass());
- if(coreConfiguration.hasBuildInfo()) {
+ if (coreConfiguration.hasBuildInfo()) {
log.info("Apache Marmotta Core Version {} starting up ... ", coreConfiguration.getModuleVersion());
log.info("Build Information:");
log.info(" - Build User: {}", coreConfiguration.getBuildUser());
@@ -119,76 +121,76 @@ public class MarmottaStartupService {
log.info("Apache Marmotta Core (Development Version) starting up ... ");
}
- if(StringUtils.isBlank(home)) {
+ if (StringUtils.isBlank(home)) {
home = System.getProperty("marmotta.home");
- if(StringUtils.isNotBlank(home)) {
+ if (StringUtils.isNotBlank(home)) {
log.info("Configured working directory {} from system property marmotta.home", home);
} else {
home = System.getProperty("lmf.home");
- if(StringUtils.isNotBlank(home)) {
+ if (StringUtils.isNotBlank(home)) {
log.info("Configured working directory {} from system property lmf.home", home);
} else {
home = System.getProperty("kiwi.home");
- if(StringUtils.isNotBlank(home)) {
+ if (StringUtils.isNotBlank(home)) {
log.info("Configured working directory {} from system property kiwi.home", home);
- } else {
- home = System.getenv("MARMOTTA_HOME");
- if(StringUtils.isNotBlank(home)) {
- log.info("Configured working directory {} from environment variable MARMOTTA_HOME", home);
- } else {
- home = System.getenv("LMF_HOME");
- if(StringUtils.isNotBlank(home)) {
- log.info("Configured working directory {} from environment variable LMF_HOME", home);
- } else {
- home = System.getenv("KIWI_HOME");
- if(StringUtils.isNotBlank(home)) {
- log.info("Configured working directory {} from environment variable KIWI_HOME", home);
- } else {
- if (context != null) {
- home = context.getInitParameter("marmotta.home");
- if(StringUtils.isNotBlank(home)) {
- log.info("Configured working directory {} from servlet context parameter marmotta.home", home);
- }
- } else {
- log.error("could not determine Apache Marmotta home directory, please set the environment variable MARMOTTA_HOME");
- }
- }
- }
- }
+ } else {
+ home = System.getenv("MARMOTTA_HOME");
+ if (StringUtils.isNotBlank(home)) {
+ log.info("Configured working directory {} from environment variable MARMOTTA_HOME", home);
+ } else {
+ home = System.getenv("LMF_HOME");
+ if (StringUtils.isNotBlank(home)) {
+ log.info("Configured working directory {} from environment variable LMF_HOME", home);
+ } else {
+ home = System.getenv("KIWI_HOME");
+ if (StringUtils.isNotBlank(home)) {
+ log.info("Configured working directory {} from environment variable KIWI_HOME", home);
+ } else {
+ if (context != null) {
+ home = context.getInitParameter("marmotta.home");
+ if (StringUtils.isNotBlank(home)) {
+ log.info("Configured working directory {} from servlet context parameter marmotta.home", home);
+ }
+ } else {
+ log.error("could not determine Apache Marmotta home directory, please set the environment variable MARMOTTA_HOME");
+ }
+ }
+ }
+ }
}
}
}
}
- if(StringUtils.isNotBlank(home)) {
- if (home.startsWith("~" + File.separator)) {
- home = System.getProperty("user.home") + home.substring(1);
- }
+ if (StringUtils.isNotBlank(home)) {
+ if (home.startsWith("~" + File.separator)) {
+ home = System.getProperty("user.home") + home.substring(1);
+ }
configurationService.setHome(home);
} else {
- log.error("home directory not properly initialized!!!");
+ log.error("home directory not properly initialized!!!");
}
- if(context != null) {
+ if (context != null) {
configurationService.setServletContext(context);
}
- configurationService.initialize(home,configurationOverride);
+ configurationService.initialize(home, configurationOverride);
configurationService.setConfiguration("kiwi.version", versionNumber);
- if(context != null) {
+ if (context != null) {
configurationService.setConfiguration("kiwi.path", context.getContextPath());
// register the systray links provided by the different components
- Map<String, String> demoLinks = new HashMap<String, String>();
+ Map<String, String> demoLinks = new HashMap<String, String>();
Map<String, String> adminLinks = new HashMap<String, String>();
- for(MarmottaSystrayLink link : CDIContext.getInstances(MarmottaSystrayLink.class)) {
- if(link.getSection() == MarmottaSystrayLink.Section.DEMO) {
+ for (MarmottaSystrayLink link : CDIContext.getInstances(MarmottaSystrayLink.class)) {
+ if (link.getSection() == MarmottaSystrayLink.Section.DEMO) {
demoLinks.put(link.getLabel(), link.getLink());
- } else if(link.getSection() == MarmottaSystrayLink.Section.ADMIN) {
+ } else if (link.getSection() == MarmottaSystrayLink.Section.ADMIN) {
adminLinks.put(link.getLabel(), link.getLink());
}
}
@@ -212,14 +214,14 @@ public class MarmottaStartupService {
* The method expects a host URL and a context URL to be given. In case the context URL is not given,
* it will be the same as the host URL.
*
- * @param hostUrl the URL of the host, used as based URL for building the Apache Marmotta web interface
- * @param contextUrl the base URL used to construct Linked Data resources
+ * @param hostUrl the URL of the host, used as based URL for building the Apache Marmotta web interface
+ * @param contextUrl the base URL used to construct Linked Data resources
*/
public void startupHost(String hostUrl, String contextUrl) {
lock.lock();
try {
- if(hostStarted) {
+ if (hostStarted) {
log.warn("Apache Marmotta Startup: host already started; ignoring subsequent startup requests");
return;
}
@@ -228,7 +230,7 @@ public class MarmottaStartupService {
boolean isSetup = configurationService.getBooleanConfiguration("kiwi.setup.host");
// carry out initializations that need the server URI to be set properly
- if(!isSetup) {
+ if (!isSetup) {
log.info("SETUP: Setting up initial host and resource configuration ({}) ...", hostUrl);
configurationService.setConfiguration("kiwi.context", contextUrl);
@@ -239,12 +241,12 @@ public class MarmottaStartupService {
// trigger startup of the sesame service once the hostname is ready (we need the correct URIs for
// default, cache and inferred context)
- SesameService sesameService = CDIContext.getInstance(SesameService.class);
+ SesameService sesameService = CDIContext.getInstance(SesameService.class);
sesameService.initialise();
sesameEvent.fire(new SesameStartupEvent());
// trigger startup of the user service once the sesame service is ready
- UserService userService = CDIContext.getInstance(UserService.class);
+ UserService userService = CDIContext.getInstance(UserService.class);
userService.createDefaultUsers();
@@ -253,7 +255,7 @@ public class MarmottaStartupService {
configurationService.setInitialising(false);
startupEvent.fire(new SystemStartupEvent());
-
+
} finally {
lock.unlock();
}
@@ -271,5 +273,5 @@ public class MarmottaStartupService {
public boolean isHostStarted() {
return hostStarted;
}
-
+
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/397cd2af/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/AbstractMarmotta.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/AbstractMarmotta.java b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/AbstractMarmotta.java
index 3694438..b4fb48b 100644
--- a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/AbstractMarmotta.java
+++ b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/AbstractMarmotta.java
@@ -42,7 +42,7 @@ import java.util.HashMap;
*/
public abstract class AbstractMarmotta {
- protected static Logger log = LoggerFactory.getLogger(EmbeddedMarmotta.class);
+ protected static Logger log = LoggerFactory.getLogger(AbstractMarmotta.class);
protected Weld weld;
protected WeldContainer container;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/397cd2af/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/JettyMarmotta.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/JettyMarmotta.java b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/JettyMarmotta.java
index c1a965f..8687377 100644
--- a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/JettyMarmotta.java
+++ b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/JettyMarmotta.java
@@ -17,10 +17,6 @@
*/
package org.apache.marmotta.platform.core.test.base;
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.util.*;
-
import org.apache.marmotta.platform.core.servlet.MarmottaResourceFilter;
import org.apache.marmotta.platform.core.test.base.jetty.TestApplication;
import org.apache.marmotta.platform.core.test.base.jetty.TestInjectorFactory;
@@ -28,31 +24,33 @@ import org.apache.marmotta.platform.core.util.CDIContext;
import org.apache.marmotta.platform.core.webservices.CoreApplication;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.FilterHolder;
-import org.eclipse.jetty.servlet.FilterMapping;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import javax.servlet.DispatcherType;
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.*;
/**
- * An extended version of the EmbeddedMarmotta which also starts a jetty servlet
+ * An extended version of the EmbeddedMarmotta which also starts a jetty servlet
* container. The context name is passed in the constructor; port could be passed,
- * a random available port will be use otherwise. The JettyMarmotta can optionally
- * take a set of web service classes as argument; if this argument is present, only
- * the given web services will be instantiated; otherwise, all configured web services
+ * a random available port will be use otherwise. The JettyMarmotta can optionally
+ * take a set of web service classes as argument; if this argument is present, only
+ * the given web services will be instantiated; otherwise, all configured web services
* will be instantiated (as in a normal webapp installation).
- *
+ *
* @author Sebastian Schaffert
* @author Sergio Fernández
*/
public class JettyMarmotta extends AbstractMarmotta {
private Server jetty;
-
+
private int port;
- private String context;
-
+ private String context;
+
public JettyMarmotta(String context) {
this(context, getRandomPort());
}
@@ -60,25 +58,25 @@ public class JettyMarmotta extends AbstractMarmotta {
public JettyMarmotta(String context, int port) {
this(context, port, (Set<Class<?>>) null);
}
-
+
public JettyMarmotta(String context, Class<?> webservice) {
this(context, getRandomPort(), webservice);
}
public JettyMarmotta(String context, int port, Class<?> webservice) {
- this(context,port, Collections.<Class<?>>singleton(webservice));
+ this(context, port, Collections.<Class<?>>singleton(webservice));
}
-
+
public JettyMarmotta(String context, Class<?>... webservices) {
this(context, getRandomPort(), webservices);
}
public JettyMarmotta(String context, int port, Class<?>... webservices) {
- this(context,port, new HashSet<Class<?>>(Arrays.asList(webservices)));
+ this(context, port, new HashSet<Class<?>>(Arrays.asList(webservices)));
}
-
+
public JettyMarmotta(String context, Set<Class<?>> webservices) {
- this(context, getRandomPort(), webservices);
+ this(context, getRandomPort(), webservices);
}
public JettyMarmotta(String context, int port, Set<Class<?>> webservices) {
@@ -86,7 +84,7 @@ public class JettyMarmotta extends AbstractMarmotta {
this.port = port;
this.context = (context != null ? context : "/");
-
+
// create a new jetty & run it on port 8080
jetty = new Server(this.port);
@@ -110,10 +108,10 @@ public class JettyMarmotta extends AbstractMarmotta {
// if a single web service is given, only register that webservice, otherwise startup the default configuration
//FilterHolder restEasyFilter = new FilterHolder(org.jboss.resteasy.plugins.server.servlet.FilterDispatcher.class);
- ServletHolder restEasyFilter = new ServletHolder(org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.class);
+ ServletHolder restEasyFilter = new ServletHolder(org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.class);
restEasyFilter.setInitParameter("resteasy.injector.factory", TestInjectorFactory.class.getCanonicalName());
- if(webservices != null) {
+ if (webservices != null) {
TestApplication.setTestedWebServices(webservices);
//restEasyFilter.setInitParameter("resteasy.resources", webservice.getName());
restEasyFilter.setInitParameter("javax.ws.rs.Application", TestApplication.class.getCanonicalName());
@@ -125,7 +123,7 @@ public class JettyMarmotta extends AbstractMarmotta {
ctx.addServlet(restEasyFilter, "/*");
try {
- jetty.start();
+ jetty.start();
String url = "http://localhost:" + this.port + this.context + "/";
startupService.startupHost(url, url);
} catch (Exception e) {
@@ -138,47 +136,47 @@ public class JettyMarmotta extends AbstractMarmotta {
try {
jetty.stop();
} catch (Exception e) {
- log.error("could not shutdown embedded jetty server" ,e);
+ log.error("could not shutdown embedded jetty server", e);
}
super.shutdown();
}
-
+
public int getPort() {
- return port;
- }
-
- public String getContext() {
- return context;
- }
-
- public static int getRandomPort() {
- Random ran = new Random();
- int port = 0;
- do {
- port = ran.nextInt(2000) + 8000;
- } while (!isPortAvailable(port));
-
- return port;
- }
-
- public static boolean isPortAvailable(final int port) {
- ServerSocket ss = null;
- try {
- ss = new ServerSocket(port);
- ss.setReuseAddress(true);
- return true;
- } catch (final IOException e) {
-
- } finally {
- if (ss != null) {
- try {
- ss.close();
- } catch (IOException e) {
-
- }
- }
- }
- return false;
- }
+ return port;
+ }
+
+ public String getContext() {
+ return context;
+ }
+
+ public static int getRandomPort() {
+ Random ran = new Random();
+ int port = 0;
+ do {
+ port = ran.nextInt(2000) + 8000;
+ } while (!isPortAvailable(port));
+
+ return port;
+ }
+
+ public static boolean isPortAvailable(final int port) {
+ ServerSocket ss = null;
+ try {
+ ss = new ServerSocket(port);
+ ss.setReuseAddress(true);
+ return true;
+ } catch (final IOException e) {
+
+ } finally {
+ if (ss != null) {
+ try {
+ ss.close();
+ } catch (IOException e) {
+
+ }
+ }
+ }
+ return false;
+ }
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/397cd2af/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/LdpWebServiceTest.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/LdpWebServiceTest.java b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/LdpWebServiceTest.java
index b329f2b..5ba9a25 100644
--- a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/LdpWebServiceTest.java
+++ b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/LdpWebServiceTest.java
@@ -62,7 +62,8 @@ public class LdpWebServiceTest {
@AfterClass
public static void shutdown() {
- marmotta.shutdown();
+ //marmotta.shutdown();
+ marmotta = null;
testResourceTTL = null;
}