added copyright header
diff --git a/core/org.eclipse.smila.http.server/code/src/org/eclipse/smila/http/server/jetty/PortConstraintSecurityHandler.java b/core/org.eclipse.smila.http.server/code/src/org/eclipse/smila/http/server/jetty/PortConstraintSecurityHandler.java
index 4249c3f..c6c98d0 100644
--- a/core/org.eclipse.smila.http.server/code/src/org/eclipse/smila/http/server/jetty/PortConstraintSecurityHandler.java
+++ b/core/org.eclipse.smila.http.server/code/src/org/eclipse/smila/http/server/jetty/PortConstraintSecurityHandler.java
@@ -1,96 +1,101 @@
-package org.eclipse.smila.http.server.jetty;
-
-import java.io.IOException;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.eclipse.jetty.security.ConstraintSecurityHandler;
-import org.eclipse.jetty.server.Request;
-import org.eclipse.smila.http.server.util.CorsUtils;
-
-/**
- * Special version of Jetty's {@link ConstraintSecurityHandler} that allows unauthenticated communication on a
- * configurable port. The use case for this is to configure SMILA with two HTTP ports: one allows unauthenticated access
- * and is used for internal communication by other services in the SMILA cluster, but is not accessible by external
- * client (e.g. blocked by a firewall). External clients can connect only to the second port which requires
- * authentication (and maybe the HTTPS protocol).
- *
- * <p>
- *
- * Example for usage in jetty.xml: Talking to port 8080 does not require authentication, on all other ports
- *
- * <pre>
- * <Set name="handler">
- * <New id="security" class="org.eclipse.smila.http.server.jetty.PortConstraintSecurityHandler">
- * <Set name="NoAuthenticationPort">8080</Set>
- * <Set name="Strict">false</Set>
- * <Set name="Authenticator">
- * <New class="org.eclipse.jetty.security.authentication.BasicAuthenticator" />
- * </Set>
- * <Set name="ConstraintMappings">
- * <Array type="org.eclipse.jetty.security.ConstraintMapping">
- * <Item>
- * <New class="org.eclipse.jetty.security.ConstraintMapping">
- * <Set name="PathSpec">/*</Set>
- * <Set name="Constraint">
- * <New class="org.eclipse.jetty.util.security.Constraint">
- * <Set name="Authenticate">true</Set>
- * <Set name="Roles">
- * <Array type="java.lang.String">
- * <Item>*</Item>
- * </Array>
- * </Set>
- * </New>
- * </Set>
- * </New>
- * </Item>
- * </Array>
- * </Set>
- * <Set name="handler">
- * <New id="Contexts" class="org.eclipse.jetty.server.handler.HandlerCollection" />
- * </Set>
- * </New>
- * </Set>
- * </pre>
- */
-public class PortConstraintSecurityHandler extends ConstraintSecurityHandler {
- private int _noAuthenticationPort;
-
- /**
- * Sets port that allows unauthenticated access. If never set or set to a value less or equal to 0, this class behaves
- * exactly like {@link ConstraintSecurityHandler} and all ports require authentication.
- */
- public void setNoAuthenticationPort(final int noAuthenticationPort) {
- _noAuthenticationPort = noAuthenticationPort;
- }
-
- /**
- * @return port for unauthenticated access.
- */
- public int getNoAuthenticationPort() {
- return _noAuthenticationPort;
- }
-
- @Override
- protected boolean checkSecurity(final Request request) {
- if (_noAuthenticationPort > 0 && request.getServerPort() == _noAuthenticationPort) {
- return false;
- }
- // needed for preflight CORS requests: OPTIONS requests should not require authentication
- if ("OPTIONS".equals(request.getMethod())) {
- return false;
- }
- return super.checkSecurity(request);
- }
-
- @Override
- public void handle(final String pathInContext, final Request baseRequest, final HttpServletRequest request,
- final HttpServletResponse response) throws IOException, ServletException {
-
- CorsUtils.setCorsResponseHandlers(request, response);
-
- super.handle(pathInContext, baseRequest, request, response);
- }
-}
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
+package org.eclipse.smila.http.server.jetty;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.security.ConstraintSecurityHandler;
+import org.eclipse.jetty.server.Request;
+import org.eclipse.smila.http.server.util.CorsUtils;
+
+/**
+ * Special version of Jetty's {@link ConstraintSecurityHandler} that allows unauthenticated communication on a
+ * configurable port. The use case for this is to configure SMILA with two HTTP ports: one allows unauthenticated access
+ * and is used for internal communication by other services in the SMILA cluster, but is not accessible by external
+ * client (e.g. blocked by a firewall). External clients can connect only to the second port which requires
+ * authentication (and maybe the HTTPS protocol).
+ *
+ * <p>
+ *
+ * Example for usage in jetty.xml: Talking to port 8080 does not require authentication, on all other ports
+ *
+ * <pre>
+ * <Set name="handler">
+ * <New id="security" class="org.eclipse.smila.http.server.jetty.PortConstraintSecurityHandler">
+ * <Set name="NoAuthenticationPort">8080</Set>
+ * <Set name="Strict">false</Set>
+ * <Set name="Authenticator">
+ * <New class="org.eclipse.jetty.security.authentication.BasicAuthenticator" />
+ * </Set>
+ * <Set name="ConstraintMappings">
+ * <Array type="org.eclipse.jetty.security.ConstraintMapping">
+ * <Item>
+ * <New class="org.eclipse.jetty.security.ConstraintMapping">
+ * <Set name="PathSpec">/*</Set>
+ * <Set name="Constraint">
+ * <New class="org.eclipse.jetty.util.security.Constraint">
+ * <Set name="Authenticate">true</Set>
+ * <Set name="Roles">
+ * <Array type="java.lang.String">
+ * <Item>*</Item>
+ * </Array>
+ * </Set>
+ * </New>
+ * </Set>
+ * </New>
+ * </Item>
+ * </Array>
+ * </Set>
+ * <Set name="handler">
+ * <New id="Contexts" class="org.eclipse.jetty.server.handler.HandlerCollection" />
+ * </Set>
+ * </New>
+ * </Set>
+ * </pre>
+ */
+public class PortConstraintSecurityHandler extends ConstraintSecurityHandler {
+ private int _noAuthenticationPort;
+
+ /**
+ * Sets port that allows unauthenticated access. If never set or set to a value less or equal to 0, this class behaves
+ * exactly like {@link ConstraintSecurityHandler} and all ports require authentication.
+ */
+ public void setNoAuthenticationPort(final int noAuthenticationPort) {
+ _noAuthenticationPort = noAuthenticationPort;
+ }
+
+ /**
+ * @return port for unauthenticated access.
+ */
+ public int getNoAuthenticationPort() {
+ return _noAuthenticationPort;
+ }
+
+ @Override
+ protected boolean checkSecurity(final Request request) {
+ if (_noAuthenticationPort > 0 && request.getServerPort() == _noAuthenticationPort) {
+ return false;
+ }
+ // needed for preflight CORS requests: OPTIONS requests should not require authentication
+ if ("OPTIONS".equals(request.getMethod())) {
+ return false;
+ }
+ return super.checkSecurity(request);
+ }
+
+ @Override
+ public void handle(final String pathInContext, final Request baseRequest, final HttpServletRequest request,
+ final HttpServletResponse response) throws IOException, ServletException {
+
+ CorsUtils.setCorsResponseHandlers(request, response);
+
+ super.handle(pathInContext, baseRequest, request, response);
+ }
+}
diff --git a/core/org.eclipse.smila.http.server/code/src/org/eclipse/smila/http/server/jetty/SingleUserLoginService.java b/core/org.eclipse.smila.http.server/code/src/org/eclipse/smila/http/server/jetty/SingleUserLoginService.java
index 97d845a..6cf307f 100644
--- a/core/org.eclipse.smila.http.server/code/src/org/eclipse/smila/http/server/jetty/SingleUserLoginService.java
+++ b/core/org.eclipse.smila.http.server/code/src/org/eclipse/smila/http/server/jetty/SingleUserLoginService.java
@@ -1,81 +1,86 @@
-package org.eclipse.smila.http.server.jetty;
-
-import java.io.IOException;
-
-import org.eclipse.jetty.security.ConstraintSecurityHandler;
-import org.eclipse.jetty.security.MappedLoginService;
-import org.eclipse.jetty.server.UserIdentity;
-import org.eclipse.jetty.util.security.Credential;
-import org.eclipse.jetty.util.security.Password;
-
-/**
- * Simple Jetty LoginService that allows exactly one user/password combination. The password can be given in the
- * password formats usually supported by Jetty: plain text (just the password string), MD5 (prefix "MD5:" plus hash), or
- * encrypted (prefix "CRYPT:" plus encrypted password). You can use the {@link Password} utility to create the hashed or
- * encrypted versions.
- * <p>
- * This LoginService does currently not support definition of user roles, so the security handler must be configured to
- * allow access for "any role" if used with this LoginService (e.g. for the {@link ConstraintSecurityHandler} the
- * "Strict" option must be disabled).
- * <p>
- *
- * Example for usage in jetty.xml:
- *
- * <pre>
- * <Call name="addBean">
- * <Arg>
- * <New id="LoginService" class="org.eclipse.smila.http.server.jetty.SingleUserLoginService">
- * <Set name="name">SMILA Realm</Set>
- * <Set name="user">admin</Set>
- * <Set name="password">MD5:21232f297a57a5a743894a0e4a801fc3</Set>
- * </New>
- * </Arg>
- * </Call>
- * </pre>
- */
-public class SingleUserLoginService extends MappedLoginService {
-
- private String _userName;
-
- private String _password;
-
- /** @return accepted user name. */
- public String getUser() {
- return _userName;
- }
-
- /** set user name to accept. */
- public void setUser(final String userName) {
- this._userName = userName;
- }
-
- /** @return password to accept. */
- public String getPassword() {
- return _password;
- }
-
- /** set password to accept, as plain text, MD5 hash, or encrypted. */
- public void setPassword(final String password) {
- _password = password;
- }
-
- @Override
- protected void doStart() throws Exception {
- super.doStart();
-
- final Credential credential = Credential.getCredential(_password);
- putUser(_userName, credential, null); // TODO do we need to define a role?
- }
-
- @Override
- protected UserIdentity loadUser(final String username) {
- // nothing to do
- return null;
- }
-
- @Override
- protected void loadUsers() throws IOException {
- // nothing to do
- }
-
-}
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
+package org.eclipse.smila.http.server.jetty;
+
+import java.io.IOException;
+
+import org.eclipse.jetty.security.ConstraintSecurityHandler;
+import org.eclipse.jetty.security.MappedLoginService;
+import org.eclipse.jetty.server.UserIdentity;
+import org.eclipse.jetty.util.security.Credential;
+import org.eclipse.jetty.util.security.Password;
+
+/**
+ * Simple Jetty LoginService that allows exactly one user/password combination. The password can be given in the
+ * password formats usually supported by Jetty: plain text (just the password string), MD5 (prefix "MD5:" plus hash), or
+ * encrypted (prefix "CRYPT:" plus encrypted password). You can use the {@link Password} utility to create the hashed or
+ * encrypted versions.
+ * <p>
+ * This LoginService does currently not support definition of user roles, so the security handler must be configured to
+ * allow access for "any role" if used with this LoginService (e.g. for the {@link ConstraintSecurityHandler} the
+ * "Strict" option must be disabled).
+ * <p>
+ *
+ * Example for usage in jetty.xml:
+ *
+ * <pre>
+ * <Call name="addBean">
+ * <Arg>
+ * <New id="LoginService" class="org.eclipse.smila.http.server.jetty.SingleUserLoginService">
+ * <Set name="name">SMILA Realm</Set>
+ * <Set name="user">admin</Set>
+ * <Set name="password">MD5:21232f297a57a5a743894a0e4a801fc3</Set>
+ * </New>
+ * </Arg>
+ * </Call>
+ * </pre>
+ */
+public class SingleUserLoginService extends MappedLoginService {
+
+ private String _userName;
+
+ private String _password;
+
+ /** @return accepted user name. */
+ public String getUser() {
+ return _userName;
+ }
+
+ /** set user name to accept. */
+ public void setUser(final String userName) {
+ this._userName = userName;
+ }
+
+ /** @return password to accept. */
+ public String getPassword() {
+ return _password;
+ }
+
+ /** set password to accept, as plain text, MD5 hash, or encrypted. */
+ public void setPassword(final String password) {
+ _password = password;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+
+ final Credential credential = Credential.getCredential(_password);
+ putUser(_userName, credential, null); // TODO do we need to define a role?
+ }
+
+ @Override
+ protected UserIdentity loadUser(final String username) {
+ // nothing to do
+ return null;
+ }
+
+ @Override
+ protected void loadUsers() throws IOException {
+ // nothing to do
+ }
+
+}
diff --git a/core/org.eclipse.smila.jobmanager.test/code/src/org/eclipse/smila/jobmanager/test/TestJobManagerNonForkingWorkflow.java b/core/org.eclipse.smila.jobmanager.test/code/src/org/eclipse/smila/jobmanager/test/TestJobManagerNonForkingWorkflow.java
index 2150ab7..2defb48 100644
--- a/core/org.eclipse.smila.jobmanager.test/code/src/org/eclipse/smila/jobmanager/test/TestJobManagerNonForkingWorkflow.java
+++ b/core/org.eclipse.smila.jobmanager.test/code/src/org/eclipse/smila/jobmanager/test/TestJobManagerNonForkingWorkflow.java
@@ -1,199 +1,204 @@
-package org.eclipse.smila.jobmanager.test;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.smila.common.definitions.AccessAny;
-import org.eclipse.smila.datamodel.AnyMap;
-import org.eclipse.smila.jobmanager.definitions.JobDefinition;
-import org.eclipse.smila.objectstore.ObjectStoreService;
-import org.eclipse.smila.taskmanager.BulkInfo;
-import org.eclipse.smila.taskmanager.ResultDescription;
-import org.eclipse.smila.taskmanager.Task;
-import org.eclipse.smila.taskmanager.TaskCompletionStatus;
-
-/**
- * Tests for deletion of temp objects for non-forking workflows.
- */
-public class TestJobManagerNonForkingWorkflow extends JobTaskProcessingTestBase {
-
- /** Dummy data to write into the store. */
- private static final byte[] DEAD_BEEF = new byte[] { (byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xEF };
-
- /** The initial worker's name (startAction worker). */
- private static final String INPUT_WORKER = "inputWorker";
-
- /** The workflow name. */
- private static final String WORKFLOW_NAME = "testWorkflow";
-
- /** The job name. */
- private static final String JOB_NAME = "testjob";
-
- /** The index name. */
- private static final String PARAM_VALUE = "test";
-
- /** The store name. */
- private static final String STORE_NAME = "test";
-
- /** The object store service. */
- private ObjectStoreService _defStorage;
-
- /** The jobId (to be able to finish it when test is finished. */
- private String _jobId;
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- _defStorage = getService(ObjectStoreService.class);
- for (final String storeName : _objectStoreService.getStoreNames()) {
- if ("jobmanager".equals(storeName)) {
- _objectStoreService.clearStore(storeName);
- } else {
- _objectStoreService.removeStore(storeName);
- }
- }
- _defStorage.ensureStore(STORE_NAME);
-
- // default job
- final AnyMap jobAny = AccessAny.FACTORY.createAnyMap();
- jobAny.put("name", JOB_NAME);
- final AnyMap parametersAny = AccessAny.FACTORY.createAnyMap();
- parametersAny.put("workerParameter", PARAM_VALUE);
- parametersAny.put("tempStore", STORE_NAME);
- parametersAny.put("store", STORE_NAME);
- jobAny.put("parameters", parametersAny);
- jobAny.put("workflow", WORKFLOW_NAME);
- _defPersistence.addJob(new JobDefinition(jobAny));
-
- _jobId = _jobRunEngine.startJob(JOB_NAME);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- _jobRunEngine.finishJob(JOB_NAME, _jobId);
- _defPersistence.removeJob(JOB_NAME);
- }
-
- public void testDeleteTransientBulksOfSuccessfulTask() throws Exception {
- Task task = _jobTaskProcessor.getInitialTask(INPUT_WORKER, JOB_NAME);
- // create the 1st worker's output
- final List<String> objIds1 = createOutputObjects(task);
- assertEquals(1, objIds1.size());
- assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds1.get(0)));
-
- final ResultDescription resultDescription =
- new ResultDescription(TaskCompletionStatus.SUCCESSFUL, null, null, null);
-
- // finish the 1st worker's task and get the 2nd worker's task
- task = getSingleNextTask(task, resultDescription, "intermediateWorker");
- // create the 2nd worker's output
- final List<String> objIds2 = createOutputObjects(task);
- assertEquals(1, objIds2.size());
- assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds1.get(0)));
- assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds2.get(0)));
-
- // finish the 2nd worker's task and get the 3rd worker's task
- task = getSingleNextTask(task, resultDescription, "finalWorker");
- // create the 3rd worker's output
- final List<String> objIds3 = createOutputObjects(task);
- assertEquals(1, objIds3.size());
- // the 1st worker's output does not exist because its bucket is transient
- assertFalse(_objectStoreService.existsObject(STORE_NAME, objIds1.get(0)));
- // the 2nd worker's output exists because its input bucket is persistent
- assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds2.get(0)));
- assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds3.get(0)));
-
- assertTrue(getNextTasks(task, resultDescription).isEmpty());
- }
-
- public void testDoNotDeleteTransientBulksOfTaskOnFatalError() throws Exception {
- Task task = _jobTaskProcessor.getInitialTask(INPUT_WORKER, JOB_NAME);
- // create the 1st worker's output
- final List<String> objIds1 = createOutputObjects(task);
- assertEquals(1, objIds1.size());
- assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds1.get(0)));
-
- final ResultDescription resultDescSuccessful =
- new ResultDescription(TaskCompletionStatus.SUCCESSFUL, null, null, null);
-
- // finish the 1st worker's task and get the 2nd worker's task
- task = getSingleNextTask(task, resultDescSuccessful, "intermediateWorker");
- // create the 2nd worker's output
- final List<String> objIds2 = createOutputObjects(task);
- assertEquals(1, objIds2.size());
- assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds1.get(0)));
- assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds2.get(0)));
-
- final ResultDescription resultDescriptionFatalError =
- new ResultDescription(TaskCompletionStatus.FATAL_ERROR, null, null, null);
-
- // finish the 2nd worker's task and get the 3rd worker's task
- final Task finishTask = task.createFinishTask(resultDescriptionFatalError, getClass().getSimpleName());
- final List<Task> nextTasks = _jobTaskProcessor.finishTask(finishTask);
- assertEquals(0, nextTasks.size());
-
- // the 1st worker's output exists even if its bucket is transient
- // because the task completion status is other than SUCCESSFUL
- assertFalse(_objectStoreService.existsObject(STORE_NAME, objIds1.get(0)));
- }
-
- public void testDoNotDeleteTransientBulksOfRecoverableTask() throws Exception {
- Task task = _jobTaskProcessor.getInitialTask(INPUT_WORKER, JOB_NAME);
- // create the 1st worker's output
- final List<String> objIds1 = createOutputObjects(task);
- assertEquals(1, objIds1.size());
- assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds1.get(0)));
-
- final ResultDescription resultDescSuccessful =
- new ResultDescription(TaskCompletionStatus.SUCCESSFUL, null, null, null);
-
- // finish the 1st worker's task and get the 2nd worker's task
- task = getSingleNextTask(task, resultDescSuccessful, "intermediateWorker");
- // create the 2nd worker's output
- final List<String> objIds2 = createOutputObjects(task);
- assertEquals(1, objIds2.size());
- assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds1.get(0)));
- assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds2.get(0)));
-
- final ResultDescription resultDescRecoverableError =
- new ResultDescription(TaskCompletionStatus.RECOVERABLE_ERROR, null, null, null);
-
- // finish the 2nd worker's task as recoverable and get a retry task
- task = getSingleNextTask(task, resultDescRecoverableError, "intermediateWorker");
- // the 1st worker's output is not deleted because the retry task needs it
- assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds1.get(0)));
-
- // finish the 2nd worker's task as successful and get the 3rd worker's task
- task = getSingleNextTask(task, resultDescSuccessful, "finalWorker");
- // create the 3rd worker's output
- final List<String> objIds3 = createOutputObjects(task);
- assertEquals(1, objIds3.size());
- // the 1st worker's output does not exist because its bucket is transient
- assertFalse(_objectStoreService.existsObject(STORE_NAME, objIds1.get(0)));
- // the 2nd worker's output exists because its input bucket is persistent
- assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds2.get(0)));
- assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds3.get(0)));
-
- assertTrue(getNextTasks(task, resultDescSuccessful).isEmpty());
- }
-
- private List<String> createOutputObjects(final Task task) throws Exception {
- final List<String> objectNames = new ArrayList<String>();
- for (final List<BulkInfo> bulkInfoList : task.getOutputBulks().values()) {
- for (final BulkInfo bulkInfo : bulkInfoList) {
- final String objectName = bulkInfo.getObjectName();
- _defStorage.putObject(bulkInfo.getStoreName(), objectName, DEAD_BEEF);
- _objectStoreService.putObject(bulkInfo.getStoreName(), objectName, DEAD_BEEF);
- objectNames.add(objectName);
- }
- }
- return objectNames;
- }
-}
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
+package org.eclipse.smila.jobmanager.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.smila.common.definitions.AccessAny;
+import org.eclipse.smila.datamodel.AnyMap;
+import org.eclipse.smila.jobmanager.definitions.JobDefinition;
+import org.eclipse.smila.objectstore.ObjectStoreService;
+import org.eclipse.smila.taskmanager.BulkInfo;
+import org.eclipse.smila.taskmanager.ResultDescription;
+import org.eclipse.smila.taskmanager.Task;
+import org.eclipse.smila.taskmanager.TaskCompletionStatus;
+
+/**
+ * Tests for deletion of temp objects for non-forking workflows.
+ */
+public class TestJobManagerNonForkingWorkflow extends JobTaskProcessingTestBase {
+
+ /** Dummy data to write into the store. */
+ private static final byte[] DEAD_BEEF = new byte[] { (byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xEF };
+
+ /** The initial worker's name (startAction worker). */
+ private static final String INPUT_WORKER = "inputWorker";
+
+ /** The workflow name. */
+ private static final String WORKFLOW_NAME = "testWorkflow";
+
+ /** The job name. */
+ private static final String JOB_NAME = "testjob";
+
+ /** The index name. */
+ private static final String PARAM_VALUE = "test";
+
+ /** The store name. */
+ private static final String STORE_NAME = "test";
+
+ /** The object store service. */
+ private ObjectStoreService _defStorage;
+
+ /** The jobId (to be able to finish it when test is finished. */
+ private String _jobId;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ _defStorage = getService(ObjectStoreService.class);
+ for (final String storeName : _objectStoreService.getStoreNames()) {
+ if ("jobmanager".equals(storeName)) {
+ _objectStoreService.clearStore(storeName);
+ } else {
+ _objectStoreService.removeStore(storeName);
+ }
+ }
+ _defStorage.ensureStore(STORE_NAME);
+
+ // default job
+ final AnyMap jobAny = AccessAny.FACTORY.createAnyMap();
+ jobAny.put("name", JOB_NAME);
+ final AnyMap parametersAny = AccessAny.FACTORY.createAnyMap();
+ parametersAny.put("workerParameter", PARAM_VALUE);
+ parametersAny.put("tempStore", STORE_NAME);
+ parametersAny.put("store", STORE_NAME);
+ jobAny.put("parameters", parametersAny);
+ jobAny.put("workflow", WORKFLOW_NAME);
+ _defPersistence.addJob(new JobDefinition(jobAny));
+
+ _jobId = _jobRunEngine.startJob(JOB_NAME);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ _jobRunEngine.finishJob(JOB_NAME, _jobId);
+ _defPersistence.removeJob(JOB_NAME);
+ }
+
+ public void testDeleteTransientBulksOfSuccessfulTask() throws Exception {
+ Task task = _jobTaskProcessor.getInitialTask(INPUT_WORKER, JOB_NAME);
+ // create the 1st worker's output
+ final List<String> objIds1 = createOutputObjects(task);
+ assertEquals(1, objIds1.size());
+ assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds1.get(0)));
+
+ final ResultDescription resultDescription =
+ new ResultDescription(TaskCompletionStatus.SUCCESSFUL, null, null, null);
+
+ // finish the 1st worker's task and get the 2nd worker's task
+ task = getSingleNextTask(task, resultDescription, "intermediateWorker");
+ // create the 2nd worker's output
+ final List<String> objIds2 = createOutputObjects(task);
+ assertEquals(1, objIds2.size());
+ assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds1.get(0)));
+ assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds2.get(0)));
+
+ // finish the 2nd worker's task and get the 3rd worker's task
+ task = getSingleNextTask(task, resultDescription, "finalWorker");
+ // create the 3rd worker's output
+ final List<String> objIds3 = createOutputObjects(task);
+ assertEquals(1, objIds3.size());
+ // the 1st worker's output does not exist because its bucket is transient
+ assertFalse(_objectStoreService.existsObject(STORE_NAME, objIds1.get(0)));
+ // the 2nd worker's output exists because its input bucket is persistent
+ assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds2.get(0)));
+ assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds3.get(0)));
+
+ assertTrue(getNextTasks(task, resultDescription).isEmpty());
+ }
+
+ public void testDoNotDeleteTransientBulksOfTaskOnFatalError() throws Exception {
+ Task task = _jobTaskProcessor.getInitialTask(INPUT_WORKER, JOB_NAME);
+ // create the 1st worker's output
+ final List<String> objIds1 = createOutputObjects(task);
+ assertEquals(1, objIds1.size());
+ assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds1.get(0)));
+
+ final ResultDescription resultDescSuccessful =
+ new ResultDescription(TaskCompletionStatus.SUCCESSFUL, null, null, null);
+
+ // finish the 1st worker's task and get the 2nd worker's task
+ task = getSingleNextTask(task, resultDescSuccessful, "intermediateWorker");
+ // create the 2nd worker's output
+ final List<String> objIds2 = createOutputObjects(task);
+ assertEquals(1, objIds2.size());
+ assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds1.get(0)));
+ assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds2.get(0)));
+
+ final ResultDescription resultDescriptionFatalError =
+ new ResultDescription(TaskCompletionStatus.FATAL_ERROR, null, null, null);
+
+ // finish the 2nd worker's task and get the 3rd worker's task
+ final Task finishTask = task.createFinishTask(resultDescriptionFatalError, getClass().getSimpleName());
+ final List<Task> nextTasks = _jobTaskProcessor.finishTask(finishTask);
+ assertEquals(0, nextTasks.size());
+
+ // the 1st worker's output exists even if its bucket is transient
+ // because the task completion status is other than SUCCESSFUL
+ assertFalse(_objectStoreService.existsObject(STORE_NAME, objIds1.get(0)));
+ }
+
+ public void testDoNotDeleteTransientBulksOfRecoverableTask() throws Exception {
+ Task task = _jobTaskProcessor.getInitialTask(INPUT_WORKER, JOB_NAME);
+ // create the 1st worker's output
+ final List<String> objIds1 = createOutputObjects(task);
+ assertEquals(1, objIds1.size());
+ assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds1.get(0)));
+
+ final ResultDescription resultDescSuccessful =
+ new ResultDescription(TaskCompletionStatus.SUCCESSFUL, null, null, null);
+
+ // finish the 1st worker's task and get the 2nd worker's task
+ task = getSingleNextTask(task, resultDescSuccessful, "intermediateWorker");
+ // create the 2nd worker's output
+ final List<String> objIds2 = createOutputObjects(task);
+ assertEquals(1, objIds2.size());
+ assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds1.get(0)));
+ assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds2.get(0)));
+
+ final ResultDescription resultDescRecoverableError =
+ new ResultDescription(TaskCompletionStatus.RECOVERABLE_ERROR, null, null, null);
+
+ // finish the 2nd worker's task as recoverable and get a retry task
+ task = getSingleNextTask(task, resultDescRecoverableError, "intermediateWorker");
+ // the 1st worker's output is not deleted because the retry task needs it
+ assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds1.get(0)));
+
+ // finish the 2nd worker's task as successful and get the 3rd worker's task
+ task = getSingleNextTask(task, resultDescSuccessful, "finalWorker");
+ // create the 3rd worker's output
+ final List<String> objIds3 = createOutputObjects(task);
+ assertEquals(1, objIds3.size());
+ // the 1st worker's output does not exist because its bucket is transient
+ assertFalse(_objectStoreService.existsObject(STORE_NAME, objIds1.get(0)));
+ // the 2nd worker's output exists because its input bucket is persistent
+ assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds2.get(0)));
+ assertTrue(_objectStoreService.existsObject(STORE_NAME, objIds3.get(0)));
+
+ assertTrue(getNextTasks(task, resultDescSuccessful).isEmpty());
+ }
+
+ private List<String> createOutputObjects(final Task task) throws Exception {
+ final List<String> objectNames = new ArrayList<String>();
+ for (final List<BulkInfo> bulkInfoList : task.getOutputBulks().values()) {
+ for (final BulkInfo bulkInfo : bulkInfoList) {
+ final String objectName = bulkInfo.getObjectName();
+ _defStorage.putObject(bulkInfo.getStoreName(), objectName, DEAD_BEEF);
+ _objectStoreService.putObject(bulkInfo.getStoreName(), objectName, DEAD_BEEF);
+ objectNames.add(objectName);
+ }
+ }
+ return objectNames;
+ }
+}
diff --git a/core/org.eclipse.smila.scripting/code/src/org/eclipse/smila/scripting/ScriptExecutor.java b/core/org.eclipse.smila.scripting/code/src/org/eclipse/smila/scripting/ScriptExecutor.java
index 9f599c5..ed76ef0 100644
--- a/core/org.eclipse.smila.scripting/code/src/org/eclipse/smila/scripting/ScriptExecutor.java
+++ b/core/org.eclipse.smila.scripting/code/src/org/eclipse/smila/scripting/ScriptExecutor.java
@@ -1,91 +1,96 @@
-package org.eclipse.smila.scripting;
-
-import org.eclipse.smila.datamodel.AnyMap;
-import org.eclipse.smila.datamodel.Record;
-
-/**
- * Load script files and executes functions.
- *
- * Notes:
- * <ul>
- * <li>MUST be used by a single thread only.</li>
- * <li>MUST be closed after use.</li>
- * </ul>
- *
- *
- * Best usage pattern:
- *
- * <pre>
- * try (ScriptExecutor executor = scriptingEngine.getScriptExecutor()) {
- * executor.loadScript("myScript");
- * executor.call("myFunction", record);
- * }
- * </pre>
- */
-public interface ScriptExecutor extends AutoCloseable {
-
- /**
- * load and execute file from scripting directory in this executor.
- *
- * @param scriptFile
- * Script file. Relative path some base directory, without suffix.
- * @return result result object from the script execution.
- * @throws ScriptingEngineException
- * error loading or executing scripts.
- */
- Object loadScript(String scriptFile) throws ScriptingEngineException;
-
- /**
- * execute the function with the given record. The function must have been defined by previous
- * {@link #loadScript(String)} calls.
- *
- * @param scriptFunction
- * name of function. The function must be able to take one argument.
- * @param record
- * record to process with the script.
- * @return result of function as a record.
- * @throws ScriptingEngineException
- * error processing the script.
- */
- Record call(String scriptFunction, Record record) throws ScriptingEngineException;
-
- /**
- * execute the function with the given map object. The function must have been defined by previous
- * {@link #loadScript(String)} calls.
- *
- * @param scriptFunction
- * name of function. The function must be able to take one argument.
- * @param arguments
- * arguments to process.
- * @return result of function as an AnyMap object.
- * @throws ScriptingEngineException
- * error processing the script.
- */
- AnyMap call(String scriptFunction, AnyMap arguments) throws ScriptingEngineException;
-
- /**
- *
- * @param extension
- * the extension to install to the ScriptExecutor
- * @throws ScriptingEngineException
- */
- void install(Installable extension) throws ScriptingEngineException;
-
- /**
- * Interface for object that add something to the ScriptExecutor.
- */
- interface Installable {
- /**
- * Does the installation.
- *
- * @param installTarget
- * an engine specific object suitable to install extensions to.
- * @throws ScriptingEngineException
- * installation failed.
- */
- void install(Object installTarget) throws ScriptingEngineException;
- }
-
- @Override
- void close();
-}
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
+package org.eclipse.smila.scripting;
+
+import org.eclipse.smila.datamodel.AnyMap;
+import org.eclipse.smila.datamodel.Record;
+
+/**
+ * Load script files and executes functions.
+ *
+ * Notes:
+ * <ul>
+ * <li>MUST be used by a single thread only.</li>
+ * <li>MUST be closed after use.</li>
+ * </ul>
+ *
+ *
+ * Best usage pattern:
+ *
+ * <pre>
+ * try (ScriptExecutor executor = scriptingEngine.getScriptExecutor()) {
+ * executor.loadScript("myScript");
+ * executor.call("myFunction", record);
+ * }
+ * </pre>
+ */
+public interface ScriptExecutor extends AutoCloseable {
+
+ /**
+ * load and execute file from scripting directory in this executor.
+ *
+ * @param scriptFile
+ * Script file. Relative path some base directory, without suffix.
+ * @return result result object from the script execution.
+ * @throws ScriptingEngineException
+ * error loading or executing scripts.
+ */
+ Object loadScript(String scriptFile) throws ScriptingEngineException;
+
+ /**
+ * execute the function with the given record. The function must have been defined by previous
+ * {@link #loadScript(String)} calls.
+ *
+ * @param scriptFunction
+ * name of function. The function must be able to take one argument.
+ * @param record
+ * record to process with the script.
+ * @return result of function as a record.
+ * @throws ScriptingEngineException
+ * error processing the script.
+ */
+ Record call(String scriptFunction, Record record) throws ScriptingEngineException;
+
+ /**
+ * execute the function with the given map object. The function must have been defined by previous
+ * {@link #loadScript(String)} calls.
+ *
+ * @param scriptFunction
+ * name of function. The function must be able to take one argument.
+ * @param arguments
+ * arguments to process.
+ * @return result of function as an AnyMap object.
+ * @throws ScriptingEngineException
+ * error processing the script.
+ */
+ AnyMap call(String scriptFunction, AnyMap arguments) throws ScriptingEngineException;
+
+ /**
+ *
+ * @param extension
+ * the extension to install to the ScriptExecutor
+ * @throws ScriptingEngineException
+ */
+ void install(Installable extension) throws ScriptingEngineException;
+
+ /**
+ * Interface for object that add something to the ScriptExecutor.
+ */
+ interface Installable {
+ /**
+ * Does the installation.
+ *
+ * @param installTarget
+ * an engine specific object suitable to install extensions to.
+ * @throws ScriptingEngineException
+ * installation failed.
+ */
+ void install(Object installTarget) throws ScriptingEngineException;
+ }
+
+ @Override
+ void close();
+}
diff --git a/core/org.eclipse.smila.scripting/code/src/org/eclipse/smila/scripting/ScriptNotFoundException.java b/core/org.eclipse.smila.scripting/code/src/org/eclipse/smila/scripting/ScriptNotFoundException.java
index 2de4708..658e40d 100644
--- a/core/org.eclipse.smila.scripting/code/src/org/eclipse/smila/scripting/ScriptNotFoundException.java
+++ b/core/org.eclipse.smila.scripting/code/src/org/eclipse/smila/scripting/ScriptNotFoundException.java
@@ -1,30 +1,35 @@
-package org.eclipse.smila.scripting;
-
-import org.eclipse.smila.utils.http.NotFoundHTTPResult;
-
-/** Thrown if a requested script does not exist in the script directory. */
-public class ScriptNotFoundException extends ScriptingEngineException implements NotFoundHTTPResult {
-
- private static final long serialVersionUID = 1L;
-
- /** Creates exception. */
- public ScriptNotFoundException(final String message, final boolean recoverable) {
- super(message, recoverable);
- }
-
- /** Creates exception. */
- public ScriptNotFoundException(final String message, final Throwable cause, final boolean recoverable) {
- super(message, cause, recoverable);
- }
-
- /** Creates exception. */
- public ScriptNotFoundException(final String message, final Throwable cause) {
- super(message, cause);
- }
-
- /** Creates exception. */
- public ScriptNotFoundException(final String message) {
- super(message);
- }
-
-}
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
+package org.eclipse.smila.scripting;
+
+import org.eclipse.smila.utils.http.NotFoundHTTPResult;
+
+/** Thrown if a requested script does not exist in the script directory. */
+public class ScriptNotFoundException extends ScriptingEngineException implements NotFoundHTTPResult {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Creates exception. */
+ public ScriptNotFoundException(final String message, final boolean recoverable) {
+ super(message, recoverable);
+ }
+
+ /** Creates exception. */
+ public ScriptNotFoundException(final String message, final Throwable cause, final boolean recoverable) {
+ super(message, cause, recoverable);
+ }
+
+ /** Creates exception. */
+ public ScriptNotFoundException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+
+ /** Creates exception. */
+ public ScriptNotFoundException(final String message) {
+ super(message);
+ }
+
+}
diff --git a/core/org.eclipse.smila.scripting/code/src/org/eclipse/smila/scripting/internal/RhinoUtils.java b/core/org.eclipse.smila.scripting/code/src/org/eclipse/smila/scripting/internal/RhinoUtils.java
index 0f6da42..c63bbef 100644
--- a/core/org.eclipse.smila.scripting/code/src/org/eclipse/smila/scripting/internal/RhinoUtils.java
+++ b/core/org.eclipse.smila.scripting/code/src/org/eclipse/smila/scripting/internal/RhinoUtils.java
@@ -1,124 +1,129 @@
-package org.eclipse.smila.scripting.internal;
-
-import java.net.URI;
-import java.nio.file.Path;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.eclipse.smila.blackboard.BlackboardFactory;
-import org.eclipse.smila.processing.PipeletTracker;
-import org.eclipse.wst.jsdt.debug.rhino.debugger.RhinoDebugger;
-import org.mozilla.javascript.Context;
-import org.mozilla.javascript.ContextFactory;
-import org.mozilla.javascript.Scriptable;
-import org.mozilla.javascript.ScriptableObject;
-import org.mozilla.javascript.commonjs.module.ModuleScriptProvider;
-import org.mozilla.javascript.commonjs.module.provider.ModuleSourceProvider;
-import org.mozilla.javascript.commonjs.module.provider.StrongCachingModuleScriptProvider;
-import org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider;
-import org.mozilla.javascript.tools.shell.Global;
-import org.osgi.framework.BundleContext;
-
-/**
- * Some helper functions around Rhino classes to hide details.
- */
-public final class RhinoUtils {
-
- private static final String SCRIPT_LOG_CATEGORY = JavascriptEngine.BUNDLE_NAME + ".js";
-
- private RhinoUtils() {
- throw new UnsupportedOperationException("RhinoUtils must not be instantiated.");
- }
-
- /**
- * Print some information about the Rhino engine to the given log.
- *
- * @param log
- * logger to use.
- */
- public static void printEngineInfo(final Log log) {
- final Context cx = Context.enter();
- try {
- log.info("Javascript engine is " + cx.getImplementationVersion());
- log.info("Language version " + cx.getLanguageVersion());
- log.info("Optimization level " + cx.getOptimizationLevel());
- log.info("Interpreter locale " + cx.getLocale());
- } finally {
- Context.exit();
- }
- }
-
- /**
- * Creates and start the Eclipse JSDT debugger interface for Rhino.
- *
- * @param connectionString
- * see https://wiki.eclipse.org/JSDT/Debug/Rhino/Embedding_Rhino_Debugger#The_Connection_String
- * @throws Exception
- * error starting the debugger.
- */
- public static void startDebugger(final String connectionString) throws Exception {
- final RhinoDebugger debugger = new RhinoDebugger(connectionString);
- debugger.start();
- ContextFactory.getGlobal().addListener(debugger);
- }
-
- /**
- * Creates a ModuleScriptProvider that loads scripts from the given directory only.
- *
- * @param scriptDirectory
- * base script directory.
- * @return script provider.
- */
- public static ModuleScriptProvider createScriptProvider(final Path scriptDirectory) {
- final List<URI> scriptDirsAsURIs = Arrays.asList(scriptDirectory.toUri());
- final ModuleSourceProvider sourceProvider = new UrlModuleSourceProvider(scriptDirsAsURIs, null, null, null);
- return new StrongCachingModuleScriptProvider(sourceProvider);
- }
-
- /**
- * Creates a Rhino base scope for SMILA script processing. The scope will already contain:
- * <ul>
- * <li>the Rhino Shell Globals as provided by {@link Global}.</li>
- * <li>a {@link PipeletBuilder} as "pipelets".</li>
- * <li>a {@link ServiceAccessor} as "services".</li>
- * <li>a default logger as "log"</li>
- * <li>a LogFactory as "LogFactory".</li>
- *
- * The scope will be sealed so that it cannot be modified by scripts.
- *
- * @param bundleContext
- * bundle context for lookup of service references.
- * @param pipeletTracker
- * the pipelet tracker service.
- * @param blackboardFactory
- * the blackboard factory service, needed to support pipelet invocations.
- * @return
- */
- public static Scriptable createBaseScope(final BundleContext bundleContext, final PipeletTracker pipeletTracker,
- final BlackboardFactory blackboardFactory) {
-
- final Context context = Context.enter();
- try {
- final ScriptableObject baseScope = context.initStandardObjects(null, true);
- final Global global = new Global(context);
- baseScope.setPrototype(global);
-
- final PipeletBuilder pipeletBuilder = new PipeletBuilder(pipeletTracker, blackboardFactory, baseScope);
- final ServiceAccessor serviceAccessor = new ServiceAccessor(bundleContext);
- final Log scriptLog = LogFactory.getLog(SCRIPT_LOG_CATEGORY);
- final LogFactory logFactory = LogFactory.getFactory();
-
- ScriptableObject.putProperty(baseScope, "pipelets", Context.javaToJS(pipeletBuilder, baseScope));
- ScriptableObject.putProperty(baseScope, "services", Context.javaToJS(serviceAccessor, baseScope));
- ScriptableObject.putProperty(baseScope, "log", Context.javaToJS(scriptLog, baseScope));
- ScriptableObject.putProperty(baseScope, "LogFactory", Context.javaToJS(logFactory, baseScope));
-
- baseScope.sealObject();
- return baseScope;
- } finally {
- Context.exit();
- }
- }
-}
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
+package org.eclipse.smila.scripting.internal;
+
+import java.net.URI;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.smila.blackboard.BlackboardFactory;
+import org.eclipse.smila.processing.PipeletTracker;
+import org.eclipse.wst.jsdt.debug.rhino.debugger.RhinoDebugger;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.ContextFactory;
+import org.mozilla.javascript.Scriptable;
+import org.mozilla.javascript.ScriptableObject;
+import org.mozilla.javascript.commonjs.module.ModuleScriptProvider;
+import org.mozilla.javascript.commonjs.module.provider.ModuleSourceProvider;
+import org.mozilla.javascript.commonjs.module.provider.StrongCachingModuleScriptProvider;
+import org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider;
+import org.mozilla.javascript.tools.shell.Global;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Some helper functions around Rhino classes to hide details.
+ */
+public final class RhinoUtils {
+
+ private static final String SCRIPT_LOG_CATEGORY = JavascriptEngine.BUNDLE_NAME + ".js";
+
+ private RhinoUtils() {
+ throw new UnsupportedOperationException("RhinoUtils must not be instantiated.");
+ }
+
+ /**
+ * Print some information about the Rhino engine to the given log.
+ *
+ * @param log
+ * logger to use.
+ */
+ public static void printEngineInfo(final Log log) {
+ final Context cx = Context.enter();
+ try {
+ log.info("Javascript engine is " + cx.getImplementationVersion());
+ log.info("Language version " + cx.getLanguageVersion());
+ log.info("Optimization level " + cx.getOptimizationLevel());
+ log.info("Interpreter locale " + cx.getLocale());
+ } finally {
+ Context.exit();
+ }
+ }
+
+ /**
+ * Creates and start the Eclipse JSDT debugger interface for Rhino.
+ *
+ * @param connectionString
+ * see https://wiki.eclipse.org/JSDT/Debug/Rhino/Embedding_Rhino_Debugger#The_Connection_String
+ * @throws Exception
+ * error starting the debugger.
+ */
+ public static void startDebugger(final String connectionString) throws Exception {
+ final RhinoDebugger debugger = new RhinoDebugger(connectionString);
+ debugger.start();
+ ContextFactory.getGlobal().addListener(debugger);
+ }
+
+ /**
+ * Creates a ModuleScriptProvider that loads scripts from the given directory only.
+ *
+ * @param scriptDirectory
+ * base script directory.
+ * @return script provider.
+ */
+ public static ModuleScriptProvider createScriptProvider(final Path scriptDirectory) {
+ final List<URI> scriptDirsAsURIs = Arrays.asList(scriptDirectory.toUri());
+ final ModuleSourceProvider sourceProvider = new UrlModuleSourceProvider(scriptDirsAsURIs, null, null, null);
+ return new StrongCachingModuleScriptProvider(sourceProvider);
+ }
+
+ /**
+ * Creates a Rhino base scope for SMILA script processing. The scope will already contain:
+ * <ul>
+ * <li>the Rhino Shell Globals as provided by {@link Global}.</li>
+ * <li>a {@link PipeletBuilder} as "pipelets".</li>
+ * <li>a {@link ServiceAccessor} as "services".</li>
+ * <li>a default logger as "log"</li>
+ * <li>a LogFactory as "LogFactory".</li>
+ *
+ * The scope will be sealed so that it cannot be modified by scripts.
+ *
+ * @param bundleContext
+ * bundle context for lookup of service references.
+ * @param pipeletTracker
+ * the pipelet tracker service.
+ * @param blackboardFactory
+ * the blackboard factory service, needed to support pipelet invocations.
+ * @return
+ */
+ public static Scriptable createBaseScope(final BundleContext bundleContext, final PipeletTracker pipeletTracker,
+ final BlackboardFactory blackboardFactory) {
+
+ final Context context = Context.enter();
+ try {
+ final ScriptableObject baseScope = context.initStandardObjects(null, true);
+ final Global global = new Global(context);
+ baseScope.setPrototype(global);
+
+ final PipeletBuilder pipeletBuilder = new PipeletBuilder(pipeletTracker, blackboardFactory, baseScope);
+ final ServiceAccessor serviceAccessor = new ServiceAccessor(bundleContext);
+ final Log scriptLog = LogFactory.getLog(SCRIPT_LOG_CATEGORY);
+ final LogFactory logFactory = LogFactory.getFactory();
+
+ ScriptableObject.putProperty(baseScope, "pipelets", Context.javaToJS(pipeletBuilder, baseScope));
+ ScriptableObject.putProperty(baseScope, "services", Context.javaToJS(serviceAccessor, baseScope));
+ ScriptableObject.putProperty(baseScope, "log", Context.javaToJS(scriptLog, baseScope));
+ ScriptableObject.putProperty(baseScope, "LogFactory", Context.javaToJS(logFactory, baseScope));
+
+ baseScope.sealObject();
+ return baseScope;
+ } finally {
+ Context.exit();
+ }
+ }
+}
diff --git a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/SolrConfig_Test.java b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/SolrConfig_Test.java
index 65f8697..6f9aebe 100755
--- a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/SolrConfig_Test.java
+++ b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/SolrConfig_Test.java
@@ -1,3 +1,8 @@
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
package org.eclipse.smila.solr;
import junit.framework.TestCase;
diff --git a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/SolrUtils_Test.java b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/SolrUtils_Test.java
index c238374..e2467a2 100755
--- a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/SolrUtils_Test.java
+++ b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/SolrUtils_Test.java
@@ -1,3 +1,8 @@
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
package org.eclipse.smila.solr;
import java.io.UnsupportedEncodingException;
diff --git a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/params/ParamsHelper_Test.java b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/params/ParamsHelper_Test.java
index 3e9c698..5de6be6 100755
--- a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/params/ParamsHelper_Test.java
+++ b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/params/ParamsHelper_Test.java
@@ -1,3 +1,8 @@
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
package org.eclipse.smila.solr.params;
import org.apache.solr.client.solrj.SolrRequest.METHOD;
diff --git a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/params/QueryParams_Test.java b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/params/QueryParams_Test.java
index bbf1bb4..64a64de 100755
--- a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/params/QueryParams_Test.java
+++ b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/params/QueryParams_Test.java
@@ -1,3 +1,8 @@
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
package org.eclipse.smila.solr.params;
import java.util.Arrays;
diff --git a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/params/SearchParams_Test.java b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/params/SearchParams_Test.java
index 65f790c..ddd411e 100755
--- a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/params/SearchParams_Test.java
+++ b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/params/SearchParams_Test.java
@@ -1,3 +1,8 @@
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
package org.eclipse.smila.solr.params;
import junit.framework.TestCase;
diff --git a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/params/SolrParams_Test.java b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/params/SolrParams_Test.java
index 342fb1e..f1003c3 100755
--- a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/params/SolrParams_Test.java
+++ b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/params/SolrParams_Test.java
@@ -1,3 +1,8 @@
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
package org.eclipse.smila.solr.params;
import java.io.IOException;
diff --git a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/params/UpdateParams_Test.java b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/params/UpdateParams_Test.java
index 2193b69..28d810c 100755
--- a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/params/UpdateParams_Test.java
+++ b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/params/UpdateParams_Test.java
@@ -1,3 +1,8 @@
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
package org.eclipse.smila.solr.params;
import org.apache.commons.lang.NullArgumentException;
diff --git a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/query/SolrQueryBuilder_Test.java b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/query/SolrQueryBuilder_Test.java
index 30c3e00..73b4668 100755
--- a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/query/SolrQueryBuilder_Test.java
+++ b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/query/SolrQueryBuilder_Test.java
@@ -1,3 +1,8 @@
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
package org.eclipse.smila.solr.query;
import java.util.Date;
diff --git a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/search/ResponseAccessor_Test.java b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/search/ResponseAccessor_Test.java
index 407bf60..008208a 100755
--- a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/search/ResponseAccessor_Test.java
+++ b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/search/ResponseAccessor_Test.java
@@ -1,3 +1,8 @@
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
package org.eclipse.smila.solr.search;
import junit.framework.TestCase;
diff --git a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/search/SolrResponseParser_Test.java b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/search/SolrResponseParser_Test.java
index 2ccbdf6..04b585e 100755
--- a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/search/SolrResponseParser_Test.java
+++ b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/search/SolrResponseParser_Test.java
@@ -1,3 +1,8 @@
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
package org.eclipse.smila.solr.search;
import java.util.ArrayList;
diff --git a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/server/CloudServers_Test.java b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/server/CloudServers_Test.java
index 4e0b6a2..3be3f0c 100755
--- a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/server/CloudServers_Test.java
+++ b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/server/CloudServers_Test.java
@@ -1,3 +1,8 @@
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
package org.eclipse.smila.solr.server;
import org.apache.solr.client.solrj.SolrServerException;
diff --git a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/server/HttpServers_Test.java b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/server/HttpServers_Test.java
index 19b99f8..17778ff 100755
--- a/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/server/HttpServers_Test.java
+++ b/core/org.eclipse.smila.solr.test/code/src/org/eclipse/smila/solr/server/HttpServers_Test.java
@@ -1,3 +1,8 @@
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
package org.eclipse.smila.solr.server;
import org.apache.solr.client.solrj.SolrServerException;
diff --git a/core/org.eclipse.smila.solr/code/src/org/eclipse/smila/solr/administration/FieldInfo.java b/core/org.eclipse.smila.solr/code/src/org/eclipse/smila/solr/administration/FieldInfo.java
index bdf4f44..2571ee8 100755
--- a/core/org.eclipse.smila.solr/code/src/org/eclipse/smila/solr/administration/FieldInfo.java
+++ b/core/org.eclipse.smila.solr/code/src/org/eclipse/smila/solr/administration/FieldInfo.java
@@ -1,3 +1,8 @@
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
package org.eclipse.smila.solr.administration;
import org.apache.commons.lang.ArrayUtils;
diff --git a/core/org.eclipse.smila.solr/code/src/org/eclipse/smila/solr/administration/SmilaCollectionAdminRequest.java b/core/org.eclipse.smila.solr/code/src/org/eclipse/smila/solr/administration/SmilaCollectionAdminRequest.java
index 301d3ef..6dbba03 100755
--- a/core/org.eclipse.smila.solr/code/src/org/eclipse/smila/solr/administration/SmilaCollectionAdminRequest.java
+++ b/core/org.eclipse.smila.solr/code/src/org/eclipse/smila/solr/administration/SmilaCollectionAdminRequest.java
@@ -1,3 +1,8 @@
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
package org.eclipse.smila.solr.administration;
import java.util.Map;
@@ -32,4 +37,4 @@
public SolrParams getParams() {
return _params;
}
-}
\ No newline at end of file
+}
diff --git a/core/org.eclipse.smila.solr/code/src/org/eclipse/smila/solr/administration/SmilaCoreAdminRequest.java b/core/org.eclipse.smila.solr/code/src/org/eclipse/smila/solr/administration/SmilaCoreAdminRequest.java
index 1da612c..2569934 100755
--- a/core/org.eclipse.smila.solr/code/src/org/eclipse/smila/solr/administration/SmilaCoreAdminRequest.java
+++ b/core/org.eclipse.smila.solr/code/src/org/eclipse/smila/solr/administration/SmilaCoreAdminRequest.java
@@ -1,3 +1,8 @@
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
package org.eclipse.smila.solr.administration;
import java.util.Map;
@@ -32,4 +37,4 @@
public SolrParams getParams() {
return _params;
}
-}
\ No newline at end of file
+}
diff --git a/core/org.eclipse.smila.tika.test/code/src/org/eclipse/smila/tika/test/manual/ManualTestMaxLength.java b/core/org.eclipse.smila.tika.test/code/src/org/eclipse/smila/tika/test/manual/ManualTestMaxLength.java
index e2ea95b..04be02a 100644
--- a/core/org.eclipse.smila.tika.test/code/src/org/eclipse/smila/tika/test/manual/ManualTestMaxLength.java
+++ b/core/org.eclipse.smila.tika.test/code/src/org/eclipse/smila/tika/test/manual/ManualTestMaxLength.java
@@ -1,29 +1,34 @@
-package org.eclipse.smila.tika.test.manual;
-
-import org.eclipse.smila.tika.test.TestMaxLength;
-
-/**
- * This test should run after removing standard tika.deps bundle and updating downloaded tika dependencies in SMILA
- * extensions.
- */
-public class ManualTestMaxLength extends TestMaxLength {
-
- /** Test txt. */
- public void testTXT() throws Exception {
- final String fileName = "test.txt";
- String result = doTextExtraction(fileName, null, null);
- assertTrue(result.startsWith("SMILA"));
- result = doTextExtraction(fileName, 3, null);
- assertEquals("SMI", result);
- }
-
- /** Test utf-8 txt. */
- public void testUTF8TXT() throws Exception {
- final String fileName = "utf-8.txt";
- String result = doTextExtraction(fileName, null, null);
- assertTrue("was: " + result, result.startsWith("\u00ea SMILA"));
- result = doTextExtraction(fileName, 5, null);
- assertEquals("\u00ea SMI", result);
- }
-
-}
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
+package org.eclipse.smila.tika.test.manual;
+
+import org.eclipse.smila.tika.test.TestMaxLength;
+
+/**
+ * This test should run after removing standard tika.deps bundle and updating downloaded tika dependencies in SMILA
+ * extensions.
+ */
+public class ManualTestMaxLength extends TestMaxLength {
+
+ /** Test txt. */
+ public void testTXT() throws Exception {
+ final String fileName = "test.txt";
+ String result = doTextExtraction(fileName, null, null);
+ assertTrue(result.startsWith("SMILA"));
+ result = doTextExtraction(fileName, 3, null);
+ assertEquals("SMI", result);
+ }
+
+ /** Test utf-8 txt. */
+ public void testUTF8TXT() throws Exception {
+ final String fileName = "utf-8.txt";
+ String result = doTextExtraction(fileName, null, null);
+ assertTrue("was: " + result, result.startsWith("\u00ea SMILA"));
+ result = doTextExtraction(fileName, 5, null);
+ assertEquals("\u00ea SMI", result);
+ }
+
+}
diff --git a/core/org.eclipse.smila.zookeeper.test/code/src/org/eclipse/smila/zookeeper/test/TestZkConfigurationUpdateWatcher.java b/core/org.eclipse.smila.zookeeper.test/code/src/org/eclipse/smila/zookeeper/test/TestZkConfigurationUpdateWatcher.java
index 8e141be..cb33afb 100644
--- a/core/org.eclipse.smila.zookeeper.test/code/src/org/eclipse/smila/zookeeper/test/TestZkConfigurationUpdateWatcher.java
+++ b/core/org.eclipse.smila.zookeeper.test/code/src/org/eclipse/smila/zookeeper/test/TestZkConfigurationUpdateWatcher.java
@@ -1,187 +1,192 @@
-package org.eclipse.smila.zookeeper.test;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
-import org.eclipse.smila.test.DeclarativeServiceTestCase;
-import org.eclipse.smila.utils.config.ConfigurationUpdateWatcher.UpdateableService;
-import org.eclipse.smila.zookeeper.ZkConfigurationUpdateWatcher;
-import org.eclipse.smila.zookeeper.ZooKeeperService;
-
-/** Tests for {@link ZkConfigurationUpdateWatcher}. */
-public class TestZkConfigurationUpdateWatcher extends DeclarativeServiceTestCase {
-
- private ZkConfigurationUpdateWatcher _watcher1;
-
- private MockService _service1;
-
- private ZkConfigurationUpdateWatcher _watcher2;
-
- private MockService _service2;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- final ZooKeeperService zkService = getService(ZooKeeperService.class);
- _watcher1 = new ZkConfigurationUpdateWatcher(zkService, "testing");
- _watcher2 = new ZkConfigurationUpdateWatcher(zkService, "testing");
- _service1 = new MockService(_watcher1);
- _service2 = new MockService(_watcher2);
- }
-
- @Override
- protected void tearDown() throws Exception {
- _watcher1.stopPolling();
- _watcher1.stopWatching();
- _watcher2.stopPolling();
- _watcher2.stopWatching();
- super.tearDown();
- }
-
- public void testWatchForConfigUpdate() throws Exception {
- final String configName = "testWatchForConfigUpdate";
- _watcher2.startWatching();
- _service1.update(configName);
- _service2.waitForNotification(configName, 1);
- _service1.update(configName);
- _service2.waitForNotification(configName, 2);
- _service1.update(configName);
- _service2.waitForNotification(configName, 3);
- }
-
- public void testWatchForConfigDelete() throws Exception {
- final String configName = "testWatchForConfigDelete";
- _watcher2.startWatching();
- _service1.update(configName + "1");
- _service1.update(configName + "2");
- _service2.waitForNotification(configName + "1", true);
- _service2.waitForNotification(configName + "2", true);
- _service1.delete(configName + "1");
- _service2.waitForNotification(configName + "1", false);
- assertTrue(_service2.getConfigNames().contains(configName + "2"));
- }
-
- public void testWatchForConfigLoadOnStart() throws Exception {
- final String configName = "testWatchForConfigLoadOnStart";
- _service2.loadOnStart(configName);
- _watcher2.startWatching();
- _service1.update(configName);
- _service2.waitForNotification(configName, 2);
- }
-
- public void testPollForConfigUpdate() throws Exception {
- final String configName = "testPollForConfigUpdate";
- _watcher2.startPolling(1);
- _service1.update(configName);
- _service2.waitForNotification(configName, true);
- }
-
- public void testPollForConfigDelete() throws Exception {
- final String configName = "testPollForConfigDelete";
- _watcher2.startPolling(1);
- _service1.update(configName + "1");
- _service1.update(configName + "2");
- _service2.waitForNotification(configName + "1", true);
- _service2.waitForNotification(configName + "2", true);
- _service1.delete(configName + "1");
- _service2.waitForNotification(configName + "1", false);
- assertTrue(_service2.getConfigNames().contains(configName + "2"));
- }
-
- public void testMultiDeleteAdd() throws Exception {
- final String configName = "testMultiDeleteAdd";
- final int noOfConfigs = 3;
- _watcher2.startWatching();
- for (int i = 0; i < noOfConfigs; i++) { // create configs 0, 1, 2
- _service1.update(configName + i);
- }
- for (int i = 0; i < noOfConfigs; i++) {
- _service2.waitForNotification(configName + i, 1);
- }
- assertFalse(_service2.getConfigNames().contains(configName + noOfConfigs));
- for (int i = 0; i < noOfConfigs; i++) { // delete configs 0, 1, 2
- _service1.delete(configName + i);
- }
- for (int i = 1; i <= noOfConfigs; i++) { // now create configs 1, 2, 3
- _service1.update(configName + i);
- }
- _service2.waitForNotification(configName + 0, false);
- for (int i = 1; i <= noOfConfigs; i++) {
- _service2.waitForNotification(configName + i, 1);
- }
- }
-
- private class MockService implements UpdateableService {
-
- private final Map<String, Integer> _configNames = new HashMap<>();
-
- private final ZkConfigurationUpdateWatcher _watcher;
-
- public MockService(final ZkConfigurationUpdateWatcher watcher) throws Exception {
- _watcher = watcher;
- _watcher.registerService(this);
- _watcher.initialize();
- }
-
- public Collection<String> getConfigNames() {
- return _configNames.keySet();
- }
-
- public void waitForNotification(final String configName, final boolean expectConfigExists) throws Exception {
- for (int i = 0; i < 50; i++) {
- if (expectConfigExists == _configNames.containsKey(configName)) {
- return;
- }
- Thread.sleep(100);
- }
- fail((expectConfigExists ? "Update" : "Delete") + " notification for '" + configName
- + "' not processed after 5 seconds.");
- }
-
- public void waitForNotification(final String configName, final Integer expectedUpdateCount) throws Exception {
- for (int i = 0; i < 50; i++) {
- if (expectedUpdateCount == _configNames.get(configName)) {
- return;
- }
- Thread.sleep(100);
- }
- fail("Not reached " + expectedUpdateCount + " updates for '" + configName
- + "' after 5 seconds, last count was " + _configNames.get(configName));
- }
-
- public void loadOnStart(final String configName) {
- updateInternal(configName);
- _watcher.configLoadedOnStart(configName, UUID.randomUUID().toString());
- }
-
- public void update(final String configName) {
- updateInternal(configName);
- _watcher.configUpdated(configName, UUID.randomUUID().toString());
- }
-
- private void updateInternal(final String configName) {
- if (_configNames.containsKey(configName)) {
- _configNames.put(configName, _configNames.get(configName) + 1);
- } else {
- _configNames.put(configName, 1);
- }
- }
-
- public void delete(final String configName) {
- _configNames.remove(configName);
- _watcher.configDeleted(configName);
- }
-
- @Override
- public void synchronizeConfiguration(final String configName, final boolean isDeleted) {
- if (isDeleted) {
- _configNames.remove(configName);
- } else {
- updateInternal(configName);
- }
- }
- }
-
-}
+/*********************************************************************************************************************
+ * Copyright (c) 2008, 2015 Empolis Information Management GmbH and brox IT Solutions GmbH. All rights reserved.
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+**********************************************************************************************************************/
+package org.eclipse.smila.zookeeper.test;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.eclipse.smila.test.DeclarativeServiceTestCase;
+import org.eclipse.smila.utils.config.ConfigurationUpdateWatcher.UpdateableService;
+import org.eclipse.smila.zookeeper.ZkConfigurationUpdateWatcher;
+import org.eclipse.smila.zookeeper.ZooKeeperService;
+
+/** Tests for {@link ZkConfigurationUpdateWatcher}. */
+public class TestZkConfigurationUpdateWatcher extends DeclarativeServiceTestCase {
+
+ private ZkConfigurationUpdateWatcher _watcher1;
+
+ private MockService _service1;
+
+ private ZkConfigurationUpdateWatcher _watcher2;
+
+ private MockService _service2;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ final ZooKeeperService zkService = getService(ZooKeeperService.class);
+ _watcher1 = new ZkConfigurationUpdateWatcher(zkService, "testing");
+ _watcher2 = new ZkConfigurationUpdateWatcher(zkService, "testing");
+ _service1 = new MockService(_watcher1);
+ _service2 = new MockService(_watcher2);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ _watcher1.stopPolling();
+ _watcher1.stopWatching();
+ _watcher2.stopPolling();
+ _watcher2.stopWatching();
+ super.tearDown();
+ }
+
+ public void testWatchForConfigUpdate() throws Exception {
+ final String configName = "testWatchForConfigUpdate";
+ _watcher2.startWatching();
+ _service1.update(configName);
+ _service2.waitForNotification(configName, 1);
+ _service1.update(configName);
+ _service2.waitForNotification(configName, 2);
+ _service1.update(configName);
+ _service2.waitForNotification(configName, 3);
+ }
+
+ public void testWatchForConfigDelete() throws Exception {
+ final String configName = "testWatchForConfigDelete";
+ _watcher2.startWatching();
+ _service1.update(configName + "1");
+ _service1.update(configName + "2");
+ _service2.waitForNotification(configName + "1", true);
+ _service2.waitForNotification(configName + "2", true);
+ _service1.delete(configName + "1");
+ _service2.waitForNotification(configName + "1", false);
+ assertTrue(_service2.getConfigNames().contains(configName + "2"));
+ }
+
+ public void testWatchForConfigLoadOnStart() throws Exception {
+ final String configName = "testWatchForConfigLoadOnStart";
+ _service2.loadOnStart(configName);
+ _watcher2.startWatching();
+ _service1.update(configName);
+ _service2.waitForNotification(configName, 2);
+ }
+
+ public void testPollForConfigUpdate() throws Exception {
+ final String configName = "testPollForConfigUpdate";
+ _watcher2.startPolling(1);
+ _service1.update(configName);
+ _service2.waitForNotification(configName, true);
+ }
+
+ public void testPollForConfigDelete() throws Exception {
+ final String configName = "testPollForConfigDelete";
+ _watcher2.startPolling(1);
+ _service1.update(configName + "1");
+ _service1.update(configName + "2");
+ _service2.waitForNotification(configName + "1", true);
+ _service2.waitForNotification(configName + "2", true);
+ _service1.delete(configName + "1");
+ _service2.waitForNotification(configName + "1", false);
+ assertTrue(_service2.getConfigNames().contains(configName + "2"));
+ }
+
+ public void testMultiDeleteAdd() throws Exception {
+ final String configName = "testMultiDeleteAdd";
+ final int noOfConfigs = 3;
+ _watcher2.startWatching();
+ for (int i = 0; i < noOfConfigs; i++) { // create configs 0, 1, 2
+ _service1.update(configName + i);
+ }
+ for (int i = 0; i < noOfConfigs; i++) {
+ _service2.waitForNotification(configName + i, 1);
+ }
+ assertFalse(_service2.getConfigNames().contains(configName + noOfConfigs));
+ for (int i = 0; i < noOfConfigs; i++) { // delete configs 0, 1, 2
+ _service1.delete(configName + i);
+ }
+ for (int i = 1; i <= noOfConfigs; i++) { // now create configs 1, 2, 3
+ _service1.update(configName + i);
+ }
+ _service2.waitForNotification(configName + 0, false);
+ for (int i = 1; i <= noOfConfigs; i++) {
+ _service2.waitForNotification(configName + i, 1);
+ }
+ }
+
+ private class MockService implements UpdateableService {
+
+ private final Map<String, Integer> _configNames = new HashMap<>();
+
+ private final ZkConfigurationUpdateWatcher _watcher;
+
+ public MockService(final ZkConfigurationUpdateWatcher watcher) throws Exception {
+ _watcher = watcher;
+ _watcher.registerService(this);
+ _watcher.initialize();
+ }
+
+ public Collection<String> getConfigNames() {
+ return _configNames.keySet();
+ }
+
+ public void waitForNotification(final String configName, final boolean expectConfigExists) throws Exception {
+ for (int i = 0; i < 50; i++) {
+ if (expectConfigExists == _configNames.containsKey(configName)) {
+ return;
+ }
+ Thread.sleep(100);
+ }
+ fail((expectConfigExists ? "Update" : "Delete") + " notification for '" + configName
+ + "' not processed after 5 seconds.");
+ }
+
+ public void waitForNotification(final String configName, final Integer expectedUpdateCount) throws Exception {
+ for (int i = 0; i < 50; i++) {
+ if (expectedUpdateCount == _configNames.get(configName)) {
+ return;
+ }
+ Thread.sleep(100);
+ }
+ fail("Not reached " + expectedUpdateCount + " updates for '" + configName
+ + "' after 5 seconds, last count was " + _configNames.get(configName));
+ }
+
+ public void loadOnStart(final String configName) {
+ updateInternal(configName);
+ _watcher.configLoadedOnStart(configName, UUID.randomUUID().toString());
+ }
+
+ public void update(final String configName) {
+ updateInternal(configName);
+ _watcher.configUpdated(configName, UUID.randomUUID().toString());
+ }
+
+ private void updateInternal(final String configName) {
+ if (_configNames.containsKey(configName)) {
+ _configNames.put(configName, _configNames.get(configName) + 1);
+ } else {
+ _configNames.put(configName, 1);
+ }
+ }
+
+ public void delete(final String configName) {
+ _configNames.remove(configName);
+ _watcher.configDeleted(configName);
+ }
+
+ @Override
+ public void synchronizeConfiguration(final String configName, final boolean isDeleted) {
+ if (isDeleted) {
+ _configNames.remove(configName);
+ } else {
+ updateInternal(configName);
+ }
+ }
+ }
+
+}