Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
BATCHEE-138 ensure we don't fail when a chunk is stopped with JobOper…
…ator, thanks a lot Christian Berger for his analyzis+report of this issue
- Loading branch information
Showing
7 changed files
with
169 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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.container.services.transaction; | ||
|
||
import java.util.Properties; | ||
|
||
import javax.batch.runtime.context.StepContext; | ||
|
||
import org.apache.batchee.container.exception.BatchContainerServiceException; | ||
import org.apache.batchee.container.exception.TransactionManagementException; | ||
import org.apache.batchee.spi.TransactionManagementService; | ||
import org.apache.batchee.spi.TransactionManagerAdapter; | ||
|
||
public class NoTxMgrBatchTransactionService implements TransactionManagementService { | ||
private final TransactionManagerAdapter adapter = new DefaultNonTransactionalManager(); | ||
|
||
@Override | ||
public void init(final Properties batchConfig) throws BatchContainerServiceException { | ||
// no-op | ||
} | ||
|
||
@Override | ||
public TransactionManagerAdapter getTransactionManager(final StepContext stepContext) throws TransactionManagementException { | ||
return adapter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,76 @@ | ||
/* | ||
* 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.container.impl; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
|
||
import java.util.List; | ||
import java.util.Properties; | ||
import java.util.concurrent.CountDownLatch; | ||
|
||
import javax.batch.api.chunk.AbstractItemReader; | ||
import javax.batch.api.chunk.AbstractItemWriter; | ||
import javax.batch.operations.JobOperator; | ||
import javax.batch.runtime.JobExecution; | ||
import javax.batch.runtime.StepExecution; | ||
|
||
import org.apache.batchee.container.services.ServicesManager; | ||
import org.apache.batchee.container.services.persistence.MemoryPersistenceManagerService; | ||
import org.apache.batchee.container.services.transaction.NoTxMgrBatchTransactionService; | ||
import org.apache.batchee.spi.PersistenceManagerService; | ||
import org.apache.batchee.spi.TransactionManagementService; | ||
import org.apache.batchee.util.Batches; | ||
import org.testng.annotations.Test; | ||
|
||
public class ChunkStepControllerTest { | ||
@Test | ||
public void earlyStop() throws InterruptedException { | ||
final JobOperator operator = new JobOperatorImpl(new ServicesManager() {{ | ||
init(new Properties() {{ | ||
setProperty(PersistenceManagerService.class.getSimpleName(), MemoryPersistenceManagerService.class.getName()); | ||
setProperty(TransactionManagementService.class.getSimpleName(), NoTxMgrBatchTransactionService.class.getName()); | ||
}}); | ||
}}); | ||
|
||
final long id = operator.start("stop-chunk", new Properties()); | ||
Reader.LATCH.await(); | ||
operator.stop(id); | ||
Batches.waitFor(operator, id); | ||
final List<StepExecution> stepExecutions = operator.getStepExecutions(id); | ||
final StepExecution stepExecution = stepExecutions.iterator().next(); | ||
assertEquals("STOPPED", stepExecution.getExitStatus()); // before (BATCHEE-138) it was FAILED | ||
} | ||
|
||
public static class Reader extends AbstractItemReader { | ||
static final CountDownLatch LATCH = new CountDownLatch(8); | ||
|
||
@Override | ||
public Object readItem() throws Exception { | ||
LATCH.countDown(); | ||
return new Object(); | ||
} | ||
} | ||
|
||
public static class Writer extends AbstractItemWriter { | ||
@Override | ||
public void writeItems(final List<Object> list) { | ||
// no-op | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,23 @@ | ||
<?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="stop-chunk" version="1.0" xmlns="http://xmlns.jcp.org/xml/ns/javaee"> | ||
<step id="test"> | ||
<chunk> | ||
<reader ref="org.apache.batchee.container.impl.ChunkStepControllerTest$Reader" /> | ||
<writer ref="org.apache.batchee.container.impl.ChunkStepControllerTest$Writer" /> | ||
</chunk> | ||
</step> | ||
</job> |