moved interface containing the clearState method to SSE; will add it to SecurityService as well; clearing servlet already finds all implementing services

This commit is contained in:
Axel Uhl committed 2014-12-01 15:53:59 +01:00
1 parent 619a801f3e
commit 6fecb642a4
8 files changed
+54 -59

No files matched your search

@@ -16,4 +16,5 @@ Require-Bundle: org.junit4;bundle-version="4.8.2",
com.sap.sse.common,
org.mockito.mockito-core;bundle-version="1.9.5",
org.objenesis;bundle-version="1.3.0",
org.hamcrest;bundle-version="1.1.0"
org.hamcrest;bundle-version="1.1.0",
com.sap.sse
@@ -10,7 +10,8 @@ Require-Bundle: javax.servlet;bundle-version="2.6.0",
com.sap.sailing.domain.common;bundle-version="1.0.0",
com.sap.sailing.server;bundle-version="1.0.0",
com.sap.sse.mongodb;bundle-version="1.0.0",
com.sap.sse.common
com.sap.sse.common,
com.sap.sse
Bundle-ClassPath: .
Web-ContextPath: /sailingserver/test-support
Import-Package: org.osgi.framework,
@@ -12,62 +12,59 @@ import javax.servlet.http.HttpServletResponse;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import com.sap.sailing.server.test.support.RacingEventServiceWithTestSupport;
import com.sap.sse.mongodb.MongoDBConfiguration;
import com.sap.sse.mongodb.MongoDBService;
import com.sap.sse.util.ClearStateTestSupport;
public class ClearStateServlet extends HttpServlet {
private static final long serialVersionUID = -880795218153271730L;
private static final String OSGI_BUNDLECONTEXT_ATTRIBUTE_NAME = "osgi-bundlecontext";
private static String TEST_DB_NAME = "winddbTest";
private ServiceTracker<RacingEventServiceWithTestSupport, RacingEventServiceWithTestSupport> racingEventTracker;
private static final String OSGI_BUNDLECONTEXT_ATTRIBUTE_NAME = "osgi-bundlecontext";
private static String TEST_DB_NAME = "winddbTest";
private ServiceTracker<ClearStateTestSupport, ClearStateTestSupport> racingEventTracker;
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
public void init(ServletConfig config) throws ServletException {
super.init(config);
ServletContext servletContext = config.getServletContext();
BundleContext bundleContext = (BundleContext) servletContext.getAttribute(OSGI_BUNDLECONTEXT_ATTRIBUTE_NAME);
this.racingEventTracker = new ServiceTracker<>(bundleContext, RacingEventServiceWithTestSupport.class.getName(), null);
this.racingEventTracker = new ServiceTracker<>(bundleContext,
ClearStateTestSupport.class.getName(), null);
this.racingEventTracker.open();
}
@Override
public void destroy() {
if(this.racingEventTracker != null) {
if (this.racingEventTracker != null) {
this.racingEventTracker.close();
}
super.destroy();
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
MongoDBConfiguration configuration = MongoDBService.INSTANCE.getConfiguration();
String databaseName = configuration.getDatabaseName();
if(TEST_DB_NAME.equals(databaseName)) {
try {
RacingEventServiceWithTestSupport racingEventService = getRacingEventService();
racingEventService.clearState();
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
} catch (Exception exception) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, exception.getMessage());
}
return;
}
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Database " + databaseName + " is not the database for testing!");
if (TEST_DB_NAME.equals(databaseName)) {
try {
ClearStateTestSupport[] services = getClearStateTestSupportServices();
for (ClearStateTestSupport service : services) {
service.clearState();
}
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
} catch (Exception exception) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, exception.getMessage());
}
return;
}
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Database " + databaseName
+ " is not the database for testing!");
}
public RacingEventServiceWithTestSupport getRacingEventService() {
return this.racingEventTracker.getService();
private ClearStateTestSupport[] getClearStateTestSupportServices() {
return this.racingEventTracker.getServices(new ClearStateTestSupport[2]);
}
}
@@ -38,7 +38,5 @@ Export-Package: com.sap.sailing.server,
com.sap.sailing.domain.racelogtrackingadapter.test",
com.sap.sailing.server.masterdata,
com.sap.sailing.server.operationaltransformation,
com.sap.sailing.server.racelog.tracking,
com.sap.sailing.server.test.support;
x-friends:="com.sap.sailing.server.gateway.test.support"
com.sap.sailing.server.racelog.tracking
@@ -27,9 +27,9 @@ import com.sap.sailing.domain.tracking.impl.GPSFixMovingImpl;
import com.sap.sailing.server.RacingEventService;
import com.sap.sailing.server.RacingEventServiceMXBean;
import com.sap.sailing.server.racelog.tracking.CachedOsgiTypeBasedServiceFinderFactory;
import com.sap.sailing.server.test.support.RacingEventServiceWithTestSupport;
import com.sap.sse.common.Util;
import com.sap.sse.replication.Replicable;
import com.sap.sse.util.ClearStateTestSupport;
public class Activator implements BundleActivator {
private static final Logger logger = Logger.getLogger(Activator.class.getName());
@@ -72,7 +72,7 @@ public class Activator implements BundleActivator {
replicableServiceProperties.put(Replicable.OSGi_Service_Registry_ID_Property_Name, racingEventService.getId().toString());
context.registerService(Replicable.class.getName(), racingEventService, replicableServiceProperties);
context.registerService(RacingEventService.class.getName(), racingEventService, null);
context.registerService(RacingEventServiceWithTestSupport.class.getName(), racingEventService, null);
context.registerService(ClearStateTestSupport.class.getName(), racingEventService, null);
Dictionary<String, String> properties = new Hashtable<String, String>();
properties.put(TypeBasedServiceFinder.TYPE, GPSFixImpl.class.getName());
@@ -182,7 +182,6 @@ import com.sap.sailing.server.operationaltransformation.UpdateStartTimeReceived;
import com.sap.sailing.server.operationaltransformation.UpdateTrackedRaceStatus;
import com.sap.sailing.server.operationaltransformation.UpdateWindAveragingTime;
import com.sap.sailing.server.operationaltransformation.UpdateWindSourcesToExclude;
import com.sap.sailing.server.test.support.RacingEventServiceWithTestSupport;
import com.sap.sailing.util.impl.LockUtil;
import com.sap.sailing.util.impl.NamedReentrantReadWriteLock;
import com.sap.sse.BuildVersion;
@@ -195,9 +194,10 @@ import com.sap.sse.common.search.ResultImpl;
import com.sap.sse.replication.OperationExecutionListener;
import com.sap.sse.replication.OperationWithResult;
import com.sap.sse.replication.ReplicationMasterDescriptor;
import com.sap.sse.util.ClearStateTestSupport;
import com.sap.sse.replication.impl.OperationWithResultWithIdWrapper;
public class RacingEventServiceImpl implements RacingEventServiceWithTestSupport, RegattaListener, LeaderboardRegistry,
public class RacingEventServiceImpl implements RacingEventService, ClearStateTestSupport, RegattaListener, LeaderboardRegistry,
Replicator {
private static final Logger logger = Logger.getLogger(RacingEventServiceImpl.class.getName());
@@ -1,14 +0,0 @@
package com.sap.sailing.server.test.support;
import com.sap.sailing.server.RacingEventService;
public interface RacingEventServiceWithTestSupport extends RacingEventService {
/**
* Wipes out the complete state. This method is only used or testing.
*
* Note: Simple properties like the time delay to the 'live' timepoint are not reseted.
*
* @throws Exception
*/
void clearState() throws Exception;
}
@@ -0,0 +1,12 @@
package com.sap.sse.util;
public interface ClearStateTestSupport {
/**
* Wipes out the complete state. This method is only used or testing. This also clears the persistent state
* accordingly which differs from the {@link Replicable#clearReplicaState()} operation which doesn't care about the
* persistent state.
*
* Note: Simple properties like the time delay to the 'live' time point are not reset.
*/
void clearState() throws Exception;
}