abdullah alamoudi has uploaded a new change for review.
https://asterix-gerrit.ics.uci.edu/1983
Change subject: [NO ISSUE][TEST] Improve Job Failure Tests
......................................................................
[NO ISSUE][TEST] Improve Job Failure Tests
- user model changes: no
- storage format changes: no
- interface changes: no
details:
- Add a check that all started jobs finished.
Change-Id: I9cdf53a88e07aaa3dc7cd11c5bb7ef9369835da6
---
M
asterixdb/asterix-app/src/main/java/org/apache/asterix/app/active/ActiveNotificationHandler.java
M
hyracks-fullstack/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/org/apache/hyracks/tests/integration/AbstractMultiNCIntegrationTest.java
A
hyracks-fullstack/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/org/apache/hyracks/tests/integration/TestJobLifecycleListener.java
3 files changed, 117 insertions(+), 1 deletion(-)
git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb
refs/changes/83/1983/1
diff --git
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/active/ActiveNotificationHandler.java
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/active/ActiveNotificationHandler.java
index d36d9b7..cbcc44f 100644
---
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/active/ActiveNotificationHandler.java
+++
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/active/ActiveNotificationHandler.java
@@ -132,6 +132,7 @@
@Override
public synchronized void notifyJobFinish(JobId jobId, JobStatus jobStatus,
List<Exception> exceptions)
throws HyracksException {
+ LOGGER.log(level, "Getting notified of job finish for JobId: " +
jobId);
EntityId entityId = jobId2EntityId.get(jobId);
if (entityId != null) {
add(new ActiveEvent(jobId, Kind.JOB_FINISHED, entityId,
Pair.of(jobStatus, exceptions)));
diff --git
a/hyracks-fullstack/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/org/apache/hyracks/tests/integration/AbstractMultiNCIntegrationTest.java
b/hyracks-fullstack/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/org/apache/hyracks/tests/integration/AbstractMultiNCIntegrationTest.java
index 18479e2..3fe17fc 100644
---
a/hyracks-fullstack/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/org/apache/hyracks/tests/integration/AbstractMultiNCIntegrationTest.java
+++
b/hyracks-fullstack/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/org/apache/hyracks/tests/integration/AbstractMultiNCIntegrationTest.java
@@ -43,13 +43,16 @@
import org.apache.hyracks.client.dataset.HyracksDataset;
import org.apache.hyracks.control.cc.BaseCCApplication;
import org.apache.hyracks.control.cc.ClusterControllerService;
+import org.apache.hyracks.control.cc.application.CCServiceContext;
import org.apache.hyracks.control.common.controllers.CCConfig;
import org.apache.hyracks.control.common.controllers.NCConfig;
import org.apache.hyracks.control.nc.NodeControllerService;
import org.apache.hyracks.control.nc.resources.memory.FrameManager;
import org.apache.hyracks.dataflow.common.comm.io.ResultFrameTupleAccessor;
import org.apache.hyracks.dataflow.common.comm.util.ByteBufferInputStream;
+import org.junit.After;
import org.junit.AfterClass;
+import org.junit.Before;
import org.junit.BeforeClass;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -67,6 +70,8 @@
private static NodeControllerService[] asterixNCs;
private static IHyracksClientConnection hcc;
+
+ private static final TestJobLifecycleListener jobLifecycleListener = new
TestJobLifecycleListener();
private final List<File> outputFiles;
@@ -91,7 +96,8 @@
ccConfig.setAppClass(DummyApplication.class.getName());
cc = new ClusterControllerService(ccConfig);
cc.start();
-
+ CCServiceContext serviceCtx = cc.getContext();
+ serviceCtx.addJobLifecycleListener(jobLifecycleListener);
asterixNCs = new NodeControllerService[ASTERIX_IDS.length];
for (int i = 0; i < ASTERIX_IDS.length; i++) {
File ioDev = new File("target" + File.separator + ASTERIX_IDS[i] +
File.separator + "ioDevice");
@@ -122,6 +128,16 @@
cc.stop();
}
+ @Before
+ public void setUp() {
+ jobLifecycleListener.reset();
+ }
+
+ @After
+ public void validate() throws Exception {
+ jobLifecycleListener.check();
+ }
+
protected JobId startJob(JobSpecification spec) throws Exception {
return hcc.startJob(spec);
}
diff --git
a/hyracks-fullstack/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/org/apache/hyracks/tests/integration/TestJobLifecycleListener.java
b/hyracks-fullstack/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/org/apache/hyracks/tests/integration/TestJobLifecycleListener.java
new file mode 100644
index 0000000..1bbf8d5
--- /dev/null
+++
b/hyracks-fullstack/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/org/apache/hyracks/tests/integration/TestJobLifecycleListener.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.hyracks.tests.integration;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.exceptions.HyracksException;
+import org.apache.hyracks.api.job.IJobLifecycleListener;
+import org.apache.hyracks.api.job.JobId;
+import org.apache.hyracks.api.job.JobSpecification;
+import org.apache.hyracks.api.job.JobStatus;
+
+@SuppressWarnings("deprecation")
+public class TestJobLifecycleListener implements IJobLifecycleListener {
+
+ private static final Logger LOGGER =
Logger.getLogger(TestJobLifecycleListener.class.getName());
+ private final Map<JobId, JobSpecification> created = new HashMap<>();
+ private final Set<JobId> started = new HashSet<>();
+ private final Set<JobId> finished = new HashSet<>();
+
+ @Override
+ public void notifyJobCreation(JobId jobId, JobSpecification spec) throws
HyracksException {
+ if (created.containsKey(jobId)) {
+ throw new HyracksDataException("Job " + jobId + "has been created
before");
+ }
+ created.put(jobId, spec);
+ }
+
+ @Override
+ public void notifyJobStart(JobId jobId) throws HyracksException {
+ if (!created.containsKey(jobId)) {
+ throw new HyracksDataException("Job " + jobId + "has not been
created");
+ }
+ if (started.contains(jobId)) {
+ throw new HyracksDataException("Job " + jobId + "has been started
before");
+ }
+ started.add(jobId);
+ }
+
+ @Override
+ public void notifyJobFinish(JobId jobId, JobStatus jobStatus,
List<Exception> exceptions) throws HyracksException {
+ if (!started.contains(jobId)) {
+ throw new HyracksDataException("Job " + jobId + "has not been
started");
+ }
+ if (finished.contains(jobId)) {
+ // TODO: job finish should be called once only when it has really
completed
+ // throw new HyracksDataException("Job " + jobId + "has been
finished before");
+ LOGGER.log(Level.WARNING, "Dangerous: Duplicate Job: " + jobId + "
has finished with status: " + jobStatus);
+ } else {
+ LOGGER.log(Level.WARNING, "Job: " + jobId + " has finished with
status: " + jobStatus);
+ }
+ finished.add(jobId);
+ }
+
+ public void reset() {
+ created.clear();
+ started.clear();
+ finished.clear();
+ }
+
+ public void check() throws Exception {
+ LOGGER.log(Level.WARNING, "Checking all created jobs have started");
+ for (JobId jobId : created.keySet()) {
+ if (!started.contains(jobId)) {
+ throw new Exception("JobId " + jobId + " has been created but
never started");
+ }
+ }
+ LOGGER.log(Level.WARNING, "Checking all started jobs have terminated");
+ for (JobId jobId : started) {
+ if (!finished.contains(jobId)) {
+ throw new Exception("JobId " + jobId + " has started but not
finished");
+ }
+ }
+ LOGGER.log(Level.WARNING, "All is good");
+ }
+}
--
To view, visit https://asterix-gerrit.ics.uci.edu/1983
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9cdf53a88e07aaa3dc7cd11c5bb7ef9369835da6
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: abdullah alamoudi <[email protected]>