You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@batchee.apache.org by st...@apache.org on 2016/05/15 19:58:00 UTC

[1/3] incubator-batchee git commit: BATCHEE-88 unit test which shows the broken TX error handling

Repository: incubator-batchee
Updated Branches:
  refs/heads/master 88041b923 -> 7a74df4bc


BATCHEE-88 unit test which shows the broken TX error handling


Project: http://git-wip-us.apache.org/repos/asf/incubator-batchee/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-batchee/commit/4313c770
Tree: http://git-wip-us.apache.org/repos/asf/incubator-batchee/tree/4313c770
Diff: http://git-wip-us.apache.org/repos/asf/incubator-batchee/diff/4313c770

Branch: refs/heads/master
Commit: 4313c77012a8ed43de3b0b947f9857711b11f65a
Parents: 04f73a6
Author: Mark Struberg <st...@apache.org>
Authored: Sun Jan 17 20:21:10 2016 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Sun May 15 19:01:38 2016 +0200

----------------------------------------------------------------------
 integration-tests/pom.xml                       |  47 ++++++++
 integration-tests/transaction/pom.xml           |  58 +++++++++
 .../MockTransactionManagerService.java          | 120 +++++++++++++++++++
 .../batchee/its/transaction/TxErrorReader.java  |  34 ++++++
 .../batchee/its/transaction/TxErrorTest.java    |  37 ++++++
 .../batchee/its/transaction/TxErrorWriter1.java |  37 ++++++
 .../resources/META-INF/batch-jobs/txtest1.xml   |  26 ++++
 .../src/test/resources/batchee.properties       |  16 +++
 .../batchee/spi/TransactionManagerAdapter.java  |   5 +
 pom.xml                                         |   1 +
 10 files changed, 381 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/4313c770/integration-tests/pom.xml
----------------------------------------------------------------------
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
new file mode 100644
index 0000000..06a964a
--- /dev/null
+++ b/integration-tests/pom.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.batchee</groupId>
+        <artifactId>batchee</artifactId>
+        <version>0.4-incubating-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>integration-tests</artifactId>
+    <packaging>pom</packaging>
+
+    <modules>
+        <module>transaction</module>
+    </modules>
+
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-deploy-plugin</artifactId>
+                <configuration>
+                    <!-- we do not need to deploy the whole it module -->
+                    <skip>true</skip>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/4313c770/integration-tests/transaction/pom.xml
----------------------------------------------------------------------
diff --git a/integration-tests/transaction/pom.xml b/integration-tests/transaction/pom.xml
new file mode 100644
index 0000000..ff08da9
--- /dev/null
+++ b/integration-tests/transaction/pom.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.batchee</groupId>
+        <artifactId>integration-tests</artifactId>
+        <version>0.4-incubating-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>integration-transaction</artifactId>
+    <packaging>jar</packaging>
+
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.batchee</groupId>
+            <artifactId>batchee-jbatch</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-jta_1.1_spec</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-jbatch_1.0_spec</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-atinject_1.0_spec</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.testng</groupId>
+            <artifactId>testng</artifactId>
+        </dependency>
+
+    </dependencies>
+
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/4313c770/integration-tests/transaction/src/test/java/org/apache/batchee/its/transaction/MockTransactionManagerService.java
----------------------------------------------------------------------
diff --git a/integration-tests/transaction/src/test/java/org/apache/batchee/its/transaction/MockTransactionManagerService.java b/integration-tests/transaction/src/test/java/org/apache/batchee/its/transaction/MockTransactionManagerService.java
new file mode 100644
index 0000000..5a02987
--- /dev/null
+++ b/integration-tests/transaction/src/test/java/org/apache/batchee/its/transaction/MockTransactionManagerService.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2012 International Business Machines Corp.
+ *
+ * See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. Licensed 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.batchee.its.transaction;
+
+import javax.batch.runtime.context.StepContext;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+
+import java.util.Properties;
+
+import org.apache.batchee.container.exception.TransactionManagementException;
+import org.apache.batchee.spi.TransactionManagementService;
+import org.apache.batchee.spi.TransactionManagerAdapter;
+
+/**
+ * A batchee
+ */
+public class MockTransactionManagerService implements TransactionManagementService {
+
+    public static MockTransactionManagerAdapter mockTxAdapter = new MockTransactionManagerAdapter();
+
+    @Override
+    public TransactionManagerAdapter getTransactionManager(StepContext stepContext)
+    {
+        return mockTxAdapter;
+    }
+
+    @Override
+    public void init(Properties batchConfig)
+    {
+
+    }
+
+    public static class MockTransactionManagerAdapter implements TransactionManagerAdapter
+    {
+        private int txStatus = Status.STATUS_NO_TRANSACTION;
+
+        public void setTxStatus(int txStatus)
+        {
+            this.txStatus = txStatus;
+        }
+
+        @Override
+        public void begin()
+        {
+            txStatus = Status.STATUS_ACTIVE;
+        }
+
+        @Override
+        public void commit()
+        {
+            switch (txStatus) {
+                case Status.STATUS_ACTIVE:
+                    txStatus = Status.STATUS_COMMITTED;
+                    break;
+                case Status.STATUS_ROLLEDBACK:
+                case Status.STATUS_MARKED_ROLLBACK:
+                    throw new TransactionManagementException(new RollbackException());
+                default :
+                    throw new TransactionManagementException(new IllegalStateException("no mock-tx on current thread"));
+            }
+        }
+
+        @Override
+        public int getStatus()
+        {
+            return txStatus;
+        }
+
+        @Override
+        public void rollback()
+        {
+            switch (txStatus) {
+                case Status.STATUS_ACTIVE:
+                    txStatus = Status.STATUS_ROLLEDBACK;
+                    break;
+                case Status.STATUS_ROLLEDBACK:
+                case Status.STATUS_MARKED_ROLLBACK:
+                    break;
+                default :
+                    throw new TransactionManagementException(new IllegalStateException("no mock-tx on current thread"));
+            }
+        }
+
+        @Override
+        public void setRollbackOnly()
+        {
+            switch (txStatus) {
+                case Status.STATUS_ACTIVE:
+                case Status.STATUS_MARKED_ROLLBACK:
+                    txStatus = Status.STATUS_MARKED_ROLLBACK;
+                    break;
+                case Status.STATUS_ROLLEDBACK:
+                    break;
+                default :
+                    throw new TransactionManagementException(new IllegalStateException("no mock-tx on current thread"));
+            }
+        }
+
+        @Override
+        public void setTransactionTimeout(int arg0)
+        {
+            // no op
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/4313c770/integration-tests/transaction/src/test/java/org/apache/batchee/its/transaction/TxErrorReader.java
----------------------------------------------------------------------
diff --git a/integration-tests/transaction/src/test/java/org/apache/batchee/its/transaction/TxErrorReader.java b/integration-tests/transaction/src/test/java/org/apache/batchee/its/transaction/TxErrorReader.java
new file mode 100644
index 0000000..674db7b
--- /dev/null
+++ b/integration-tests/transaction/src/test/java/org/apache/batchee/its/transaction/TxErrorReader.java
@@ -0,0 +1,34 @@
+/*
+ * 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.batchee.its.transaction;
+
+import javax.batch.api.chunk.AbstractItemReader;
+
+/**
+ * Sample Reader which simply counts from 1..5
+ */
+public class TxErrorReader extends AbstractItemReader {
+    private int i = 1;
+
+    @Override
+    public Object readItem() throws Exception {
+        if (i > 5) {
+            return null;
+        }
+        return Integer.valueOf(i++);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/4313c770/integration-tests/transaction/src/test/java/org/apache/batchee/its/transaction/TxErrorTest.java
----------------------------------------------------------------------
diff --git a/integration-tests/transaction/src/test/java/org/apache/batchee/its/transaction/TxErrorTest.java b/integration-tests/transaction/src/test/java/org/apache/batchee/its/transaction/TxErrorTest.java
new file mode 100644
index 0000000..acdbd51
--- /dev/null
+++ b/integration-tests/transaction/src/test/java/org/apache/batchee/its/transaction/TxErrorTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.batchee.its.transaction;
+
+import javax.batch.operations.JobOperator;
+import javax.batch.runtime.BatchRuntime;
+import javax.batch.runtime.BatchStatus;
+
+import org.apache.batchee.util.Batches;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class TxErrorTest {
+
+
+    @Test
+    public void testRolledBackDuringWork() {
+        final JobOperator jobOperator = BatchRuntime.getJobOperator();
+        BatchStatus batchStatus = Batches.waitFor(jobOperator, jobOperator.start("txtest1", null));
+        Assert.assertEquals(batchStatus, BatchStatus.COMPLETED);
+        Assert.assertEquals(TxErrorWriter1.written.intValue(), 5);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/4313c770/integration-tests/transaction/src/test/java/org/apache/batchee/its/transaction/TxErrorWriter1.java
----------------------------------------------------------------------
diff --git a/integration-tests/transaction/src/test/java/org/apache/batchee/its/transaction/TxErrorWriter1.java b/integration-tests/transaction/src/test/java/org/apache/batchee/its/transaction/TxErrorWriter1.java
new file mode 100644
index 0000000..4a3dcfe
--- /dev/null
+++ b/integration-tests/transaction/src/test/java/org/apache/batchee/its/transaction/TxErrorWriter1.java
@@ -0,0 +1,37 @@
+/*
+ * 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.batchee.its.transaction;
+
+import javax.batch.api.chunk.AbstractItemWriter;
+import javax.transaction.Status;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class TxErrorWriter1 extends AbstractItemWriter {
+    public static AtomicInteger written = new AtomicInteger(0);
+
+    @Override
+    public void writeItems(List items) throws Exception {
+        Integer i = (Integer) items.get(0);
+
+        if (i.intValue() == 3) {
+            MockTransactionManagerService.mockTxAdapter.setTxStatus(Status.STATUS_ROLLEDBACK);
+        }
+
+        written.incrementAndGet();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/4313c770/integration-tests/transaction/src/test/resources/META-INF/batch-jobs/txtest1.xml
----------------------------------------------------------------------
diff --git a/integration-tests/transaction/src/test/resources/META-INF/batch-jobs/txtest1.xml b/integration-tests/transaction/src/test/resources/META-INF/batch-jobs/txtest1.xml
new file mode 100644
index 0000000..4b7a67c
--- /dev/null
+++ b/integration-tests/transaction/src/test/resources/META-INF/batch-jobs/txtest1.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  See the NOTICE file distributed with this work for additional information
+  regarding copyright ownership. Licensed 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.
+-->
+<job id="txtest1" version="1.0" xmlns="http://xmlns.jcp.org/xml/ns/javaee">
+    <step id="txtest1-step">
+        <chunk item-count="1">
+            <reader ref="org.apache.batchee.its.transaction.TxErrorReader"></reader>
+            <writer ref="org.apache.batchee.its.transaction.TxErrorWriter1"></writer>
+            <skippable-exception-classes>
+                <include class="java.lang.Exception"/> <!-- all exceptions... -->
+            </skippable-exception-classes>
+        </chunk>
+    </step>
+</job>

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/4313c770/integration-tests/transaction/src/test/resources/batchee.properties
----------------------------------------------------------------------
diff --git a/integration-tests/transaction/src/test/resources/batchee.properties b/integration-tests/transaction/src/test/resources/batchee.properties
new file mode 100644
index 0000000..dc0cb5e
--- /dev/null
+++ b/integration-tests/transaction/src/test/resources/batchee.properties
@@ -0,0 +1,16 @@
+#
+# 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.
+TransactionManagementService=org.apache.batchee.its.transaction.MockTransactionManagerService
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/4313c770/jbatch/src/main/java/org/apache/batchee/spi/TransactionManagerAdapter.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/spi/TransactionManagerAdapter.java b/jbatch/src/main/java/org/apache/batchee/spi/TransactionManagerAdapter.java
index bd13d1d..5e89532 100755
--- a/jbatch/src/main/java/org/apache/batchee/spi/TransactionManagerAdapter.java
+++ b/jbatch/src/main/java/org/apache/batchee/spi/TransactionManagerAdapter.java
@@ -45,6 +45,11 @@ public interface TransactionManagerAdapter {
      * Roll back the transaction associated with the
      * current thread. When this method completes,
      * the thread becomes associated with no transaction.
+     *
+     * Attention: this must not throw an Exception until there is a setup problem!
+     * So if the tx is not active anymore and we get an Exception while trying
+     * to rollback then it MUST get catched away. Otoh if there is a setup
+     * or system issue the Exception from the rollback needs to get thrown.
      */
     public void rollback();
 

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/4313c770/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index a3b0f99..5384c7d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -104,6 +104,7 @@
         <module>gui</module>
         <module>tools</module>
         <module>test</module>
+        <module>integration-tests</module>
     </modules>
 
     <dependencyManagement>


[2/3] incubator-batchee git commit: BATCHEE-89 use geronimo spec api for jta

Posted by st...@apache.org.
BATCHEE-89 use geronimo spec api for jta

We don't need the whole geronimo transaction implementation but just the API.


Project: http://git-wip-us.apache.org/repos/asf/incubator-batchee/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-batchee/commit/04f73a64
Tree: http://git-wip-us.apache.org/repos/asf/incubator-batchee/tree/04f73a64
Diff: http://git-wip-us.apache.org/repos/asf/incubator-batchee/diff/04f73a64

Branch: refs/heads/master
Commit: 04f73a64c3a971b31fef2fd2369823e503753517
Parents: 88041b9
Author: Mark Struberg <st...@apache.org>
Authored: Sun Jan 17 20:19:26 2016 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Sun May 15 19:01:38 2016 +0200

----------------------------------------------------------------------
 extensions/extras/pom.xml | 4 ++--
 jbatch/pom.xml            | 6 +++---
 pom.xml                   | 6 +++---
 tools/ee6/pom.xml         | 4 ++--
 4 files changed, 10 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/04f73a64/extensions/extras/pom.xml
----------------------------------------------------------------------
diff --git a/extensions/extras/pom.xml b/extensions/extras/pom.xml
index a77aa50..5f95ec1 100644
--- a/extensions/extras/pom.xml
+++ b/extensions/extras/pom.xml
@@ -33,8 +33,8 @@
 
     <dependencies>
         <dependency>
-            <groupId>org.apache.geronimo.components</groupId>
-            <artifactId>geronimo-transaction</artifactId>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-jta_1.1_spec</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/04f73a64/jbatch/pom.xml
----------------------------------------------------------------------
diff --git a/jbatch/pom.xml b/jbatch/pom.xml
index 39e13fd..4a5763d 100644
--- a/jbatch/pom.xml
+++ b/jbatch/pom.xml
@@ -55,8 +55,8 @@
       <artifactId>geronimo-interceptor_1.1_spec</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.apache.geronimo.components</groupId>
-      <artifactId>geronimo-transaction</artifactId>
+      <groupId>org.apache.geronimo.specs</groupId>
+      <artifactId>geronimo-jta_1.1_spec</artifactId>
     </dependency>
     <dependency>
       <groupId>org.apache.geronimo.specs</groupId>
@@ -290,7 +290,7 @@
       <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>templating-maven-plugin</artifactId>
-        <version>1.0-alpha-3</version>
+        <version>1.0.0</version>
         <executions>
           <execution>
             <id>filter-src</id>

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/04f73a64/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 0d22bc2..a3b0f99 100644
--- a/pom.xml
+++ b/pom.xml
@@ -152,9 +152,9 @@
                 <scope>provided</scope>
             </dependency>
             <dependency>
-                <groupId>org.apache.geronimo.components</groupId>
-                <artifactId>geronimo-transaction</artifactId>
-                <version>3.1.3</version>
+                <groupId>org.apache.geronimo.specs</groupId>
+                <artifactId>geronimo-jta_1.1_spec</artifactId>
+                <version>1.1.1</version>
                 <scope>provided</scope>
             </dependency>
 

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/04f73a64/tools/ee6/pom.xml
----------------------------------------------------------------------
diff --git a/tools/ee6/pom.xml b/tools/ee6/pom.xml
index 5528e0e..f9e9e73 100644
--- a/tools/ee6/pom.xml
+++ b/tools/ee6/pom.xml
@@ -50,8 +50,8 @@
             <artifactId>geronimo-interceptor_1.1_spec</artifactId>
         </dependency>
         <dependency>
-            <groupId>org.apache.geronimo.components</groupId>
-            <artifactId>geronimo-transaction</artifactId>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-jta_1.1_spec</artifactId>
         </dependency>
 
         <dependency>


[3/3] incubator-batchee git commit: BATCHEE-88 improve handling in case of error during step commit

Posted by st...@apache.org.
BATCHEE-88 improve handling in case of error during step commit


Project: http://git-wip-us.apache.org/repos/asf/incubator-batchee/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-batchee/commit/7a74df4b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-batchee/tree/7a74df4b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-batchee/diff/7a74df4b

Branch: refs/heads/master
Commit: 7a74df4bc9295377ab35ea53eacb8204698cd425
Parents: 4313c77
Author: Mark Struberg <st...@apache.org>
Authored: Sun May 15 21:57:00 2016 +0200
Committer: Mark Struberg <st...@apache.org>
Committed: Sun May 15 21:57:00 2016 +0200

----------------------------------------------------------------------
 .../batchee/its/transaction/TxErrorTest.java    | 29 ++++++++++++++--
 .../resources/META-INF/batch-jobs/txtest1.xml   |  3 --
 .../impl/controller/BaseStepController.java     | 17 ++++++++--
 .../controller/chunk/CheckpointManager.java     | 28 +++++++++++++---
 .../controller/chunk/ChunkStepController.java   | 35 +++++++++++++++-----
 5 files changed, 92 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/7a74df4b/integration-tests/transaction/src/test/java/org/apache/batchee/its/transaction/TxErrorTest.java
----------------------------------------------------------------------
diff --git a/integration-tests/transaction/src/test/java/org/apache/batchee/its/transaction/TxErrorTest.java b/integration-tests/transaction/src/test/java/org/apache/batchee/its/transaction/TxErrorTest.java
index acdbd51..564c7a7 100644
--- a/integration-tests/transaction/src/test/java/org/apache/batchee/its/transaction/TxErrorTest.java
+++ b/integration-tests/transaction/src/test/java/org/apache/batchee/its/transaction/TxErrorTest.java
@@ -19,6 +19,10 @@ package org.apache.batchee.its.transaction;
 import javax.batch.operations.JobOperator;
 import javax.batch.runtime.BatchRuntime;
 import javax.batch.runtime.BatchStatus;
+import javax.batch.runtime.Metric;
+import javax.batch.runtime.StepExecution;
+
+import java.util.List;
 
 import org.apache.batchee.util.Batches;
 import org.testng.Assert;
@@ -30,8 +34,27 @@ public class TxErrorTest {
     @Test
     public void testRolledBackDuringWork() {
         final JobOperator jobOperator = BatchRuntime.getJobOperator();
-        BatchStatus batchStatus = Batches.waitFor(jobOperator, jobOperator.start("txtest1", null));
-        Assert.assertEquals(batchStatus, BatchStatus.COMPLETED);
-        Assert.assertEquals(TxErrorWriter1.written.intValue(), 5);
+        long executionId = jobOperator.start("txtest1", null);
+        BatchStatus batchStatus = Batches.waitFor(jobOperator, executionId);
+        Assert.assertEquals(batchStatus, BatchStatus.FAILED);
+        Assert.assertEquals(TxErrorWriter1.written.intValue(), 3);
+
+        List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
+        Assert.assertEquals(stepExecutions.size(), 1);
+        StepExecution stepExecution = stepExecutions.get(0);
+        Metric[] metrics = stepExecution.getMetrics();
+        assertMetric(Metric.MetricType.READ_COUNT, 2, metrics);
+        assertMetric(Metric.MetricType.WRITE_COUNT, 2, metrics);
+        assertMetric(Metric.MetricType.ROLLBACK_COUNT, 1, metrics);
+    }
+
+    private void assertMetric(Metric.MetricType metricType, long expected, Metric[] metrics) {
+        for (Metric metric : metrics) {
+            if (metricType.equals(metric.getType())) {
+                Assert.assertEquals(metric.getValue(), expected);
+                return;
+            }
+        }
+        Assert.fail("MetricType " + metricType + " not in collected metrics");
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/7a74df4b/integration-tests/transaction/src/test/resources/META-INF/batch-jobs/txtest1.xml
----------------------------------------------------------------------
diff --git a/integration-tests/transaction/src/test/resources/META-INF/batch-jobs/txtest1.xml b/integration-tests/transaction/src/test/resources/META-INF/batch-jobs/txtest1.xml
index 4b7a67c..ba6809f 100644
--- a/integration-tests/transaction/src/test/resources/META-INF/batch-jobs/txtest1.xml
+++ b/integration-tests/transaction/src/test/resources/META-INF/batch-jobs/txtest1.xml
@@ -18,9 +18,6 @@
         <chunk item-count="1">
             <reader ref="org.apache.batchee.its.transaction.TxErrorReader"></reader>
             <writer ref="org.apache.batchee.its.transaction.TxErrorWriter1"></writer>
-            <skippable-exception-classes>
-                <include class="java.lang.Exception"/> <!-- all exceptions... -->
-            </skippable-exception-classes>
         </chunk>
     </step>
 </job>

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/7a74df4b/jbatch/src/main/java/org/apache/batchee/container/impl/controller/BaseStepController.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/impl/controller/BaseStepController.java b/jbatch/src/main/java/org/apache/batchee/container/impl/controller/BaseStepController.java
index d07d858..63381aa 100755
--- a/jbatch/src/main/java/org/apache/batchee/container/impl/controller/BaseStepController.java
+++ b/jbatch/src/main/java/org/apache/batchee/container/impl/controller/BaseStepController.java
@@ -359,6 +359,11 @@ public abstract class BaseStepController implements ExecutionElementController {
     }
 
     protected void persistUserData() {
+        PersistentDataWrapper userData = resolveUserData();
+        storeUserData(userData);
+    }
+
+    protected PersistentDataWrapper resolveUserData() {
         final ByteArrayOutputStream persistentBAOS = new ByteArrayOutputStream();
         final ObjectOutputStream persistentDataOOS;
 
@@ -370,8 +375,16 @@ public abstract class BaseStepController implements ExecutionElementController {
             throw new BatchContainerServiceException("Cannot persist the persistent user data for the step.", e);
         }
 
-        stepStatus.setPersistentUserData(new PersistentDataWrapper(persistentBAOS.toByteArray()));
-        statusManagerService.updateStepStatus(stepStatus.getStepExecutionId(), stepStatus);
+        return new PersistentDataWrapper(persistentBAOS.toByteArray());
+    }
+
+    protected void storeUserData(PersistentDataWrapper userData) {
+        try {
+            stepStatus.setPersistentUserData(userData);
+            statusManagerService.updateStepStatus(stepStatus.getStepExecutionId(), stepStatus);
+        } catch (final Exception e) {
+            throw new BatchContainerServiceException("Cannot persist the persistent user data for the step.", e);
+        }
     }
 
     protected void persistExitStatusAndEndTimestamp() {

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/7a74df4b/jbatch/src/main/java/org/apache/batchee/container/impl/controller/chunk/CheckpointManager.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/impl/controller/chunk/CheckpointManager.java b/jbatch/src/main/java/org/apache/batchee/container/impl/controller/chunk/CheckpointManager.java
index 7e07450..584d737 100755
--- a/jbatch/src/main/java/org/apache/batchee/container/impl/controller/chunk/CheckpointManager.java
+++ b/jbatch/src/main/java/org/apache/batchee/container/impl/controller/chunk/CheckpointManager.java
@@ -16,6 +16,9 @@
 */
 package org.apache.batchee.container.impl.controller.chunk;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.batchee.container.exception.BatchContainerRuntimeException;
 import org.apache.batchee.container.exception.BatchContainerServiceException;
 import org.apache.batchee.spi.DataRepresentationService;
@@ -75,28 +78,45 @@ public class CheckpointManager {
         }
     }
 
-    public void checkpoint() {
+    /**
+     * Takes the current checkpoint data from the ItemReader and ItemWriter
+     * and store them in the database
+     */
+    public Map<CheckpointDataKey, CheckpointData> prepareCheckpoints() {
         final CheckpointDataKey readerChkptDK;
         final CheckpointDataKey writerChkptDK;
+        Map<CheckpointDataKey, CheckpointData> checkpoints = new HashMap<CheckpointDataKey, CheckpointData>(2);
         try {
             byte[] checkpointBytes = dataRepresentationService.toInternalRepresentation(readerProxy.checkpointInfo());
             CheckpointData readerChkptData = new CheckpointData(jobInstanceID, stepId, CheckpointType.READER);
             readerChkptData.setRestartToken(checkpointBytes);
             readerChkptDK = new CheckpointDataKey(jobInstanceID, stepId, CheckpointType.READER);
 
-            persistenceManagerService.setCheckpointData(readerChkptDK, readerChkptData);
+            checkpoints.put(readerChkptDK, readerChkptData);
 
             checkpointBytes = dataRepresentationService.toInternalRepresentation(writerProxy.checkpointInfo());
             CheckpointData writerChkptData = new CheckpointData(jobInstanceID, stepId, CheckpointType.WRITER);
             writerChkptData.setRestartToken(checkpointBytes);
             writerChkptDK = new CheckpointDataKey(jobInstanceID, stepId, CheckpointType.WRITER);
 
-            persistenceManagerService.setCheckpointData(writerChkptDK, writerChkptData);
-
+            checkpoints.put(writerChkptDK, writerChkptData);
         } catch (final Exception ex) {
             // is this what I should be throwing here?
             throw new BatchContainerServiceException("Cannot persist the checkpoint data for [" + stepId + "]", ex);
         }
+
+        return checkpoints;
+    }
+
+    public void storeCheckPoints(Map<CheckpointDataKey, CheckpointData> checkpoints) {
+        try {
+            for (Map.Entry<CheckpointDataKey, CheckpointData> checkpointEntry : checkpoints.entrySet()) {
+                persistenceManagerService.setCheckpointData(checkpointEntry.getKey(), checkpointEntry.getValue());
+            }
+        } catch (final Exception ex) {
+            throw new BatchContainerServiceException("Cannot persist the checkpoint data for [" + stepId + "]", ex);
+        }
+
     }
 
     public int checkpointTimeout() {

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/7a74df4b/jbatch/src/main/java/org/apache/batchee/container/impl/controller/chunk/ChunkStepController.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/impl/controller/chunk/ChunkStepController.java b/jbatch/src/main/java/org/apache/batchee/container/impl/controller/chunk/ChunkStepController.java
index ba256fa..6d72ccd 100755
--- a/jbatch/src/main/java/org/apache/batchee/container/impl/controller/chunk/ChunkStepController.java
+++ b/jbatch/src/main/java/org/apache/batchee/container/impl/controller/chunk/ChunkStepController.java
@@ -48,10 +48,14 @@ import javax.batch.api.chunk.listener.RetryWriteListener;
 import javax.batch.api.chunk.listener.SkipProcessListener;
 import javax.batch.api.chunk.listener.SkipReadListener;
 import javax.batch.api.chunk.listener.SkipWriteListener;
+import javax.batch.operations.BatchRuntimeException;
 import javax.batch.runtime.BatchStatus;
+import javax.transaction.Status;
+
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.BlockingQueue;
 import java.util.logging.Level;
@@ -585,11 +589,22 @@ public class ChunkStepController extends SingleThreadedStepController {
                     chunkProxy.afterChunk();
                 }
 
-                checkpointManager.checkpoint();
-
-                this.persistUserData();
-
-                transactionManager.commit();
+                Map<CheckpointDataKey, CheckpointData> checkpoints = checkpointManager.prepareCheckpoints();
+                PersistentDataWrapper userData = resolveUserData();
+                try {
+                    transactionManager.commit();
+                    storeUserData(userData);
+                    checkpointManager.storeCheckPoints(checkpoints);
+                } catch (Exception e) {
+                    // only set the Exception if we didn't blow up before anyway
+                    if (this.stepContext.getException() != null) {
+                        this.stepContext.setException(e);
+                    }
+                    if (e instanceof BatchRuntimeException) {
+                        throw e;
+                    }
+                    throw new BatchContainerServiceException("Cannot commit the transaction for the step.", e);
+                }
 
                 checkpointManager.endCheckpoint();
 
@@ -659,14 +674,15 @@ public class ChunkStepController extends SingleThreadedStepController {
      */
     private void rollback(final Throwable t) {
         try {
-            // ignore, we blow up anyway
-            transactionManager.setRollbackOnly();
             try {
                 doClose();
             } catch (Exception e) {
                 // ignore, we blow up anyway
             }
 
+            // ignore, we blow up anyway
+            transactionManager.setRollbackOnly();
+
             if (t instanceof Exception) {
                 Exception e = (Exception) t;
                 for (ChunkListener chunkProxy : chunkListeners) {
@@ -681,7 +697,10 @@ public class ChunkStepController extends SingleThreadedStepController {
             // ever come up in the spec, but seems marginally more useful.
             stepContext.getMetric(MetricImpl.MetricType.ROLLBACK_COUNT).incValue();
         } finally {
-            transactionManager.rollback();
+            int txStatus = transactionManager.getStatus();
+            if (txStatus == Status.STATUS_ACTIVE || txStatus == Status.STATUS_MARKED_ROLLBACK) {
+                transactionManager.rollback();
+            }
             throw new BatchContainerRuntimeException("Failure in Read-Process-Write Loop", t);
         }
     }