INT-4445: Fix JDBC tests for Derby
JIRA: https://jira.spring.io/browse/INT-4445 Looks like `/dataSource` temporary directory is busy in between different tests. The thought is like a high-frequently polling endpoint keeps DB resource from removing. * Explicitly `stop()` endpoint in the `JdbcMessageStoreChannelTests` * Optimize `JdbcMessageStoreChannelTests.testSendAndActivateTransactionalSend()` to rely on the short `1` millisecond TX timeout. This safes for us 10 seconds of the tests executions. * Configure all the embedded DB beans for the `ignore-failures="ALL"` as a fallback option if polling endpoint is not a cause of the concurrent resource access. **Cherry-pick to 5.0.x**
This commit is contained in:
committed by
Gary Russell
parent
af58fa4417
commit
27318c7ee5
@@ -21,7 +21,7 @@
|
||||
<jdbc:embedded-database id="dataSource" type="DERBY"/>
|
||||
|
||||
<jdbc:initialize-database data-source="dataSource"
|
||||
ignore-failures="DROPS">
|
||||
ignore-failures="ALL">
|
||||
<jdbc:script location="${int.drop.script}"/>
|
||||
<jdbc:script location="${int.schema.script}"/>
|
||||
</jdbc:initialize-database>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="DERBY"/>
|
||||
|
||||
<jdbc:initialize-database data-source="dataSource" ignore-failures="DROPS">
|
||||
<jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
|
||||
<jdbc:script location="${int.drop.script}"/>
|
||||
<jdbc:script location="${int.schema.script}"/>
|
||||
</jdbc:initialize-database>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="DERBY"/>
|
||||
|
||||
<jdbc:initialize-database data-source="dataSource" ignore-failures="DROPS">
|
||||
<jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
|
||||
<jdbc:script location="${int.drop.script}"/>
|
||||
<jdbc:script location="${int.schema.script}"/>
|
||||
</jdbc:initialize-database>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<jdbc:embedded-database id="dataSource" type="DERBY" />
|
||||
|
||||
<jdbc:initialize-database data-source="dataSource"
|
||||
ignore-failures="DROPS">
|
||||
ignore-failures="ALL">
|
||||
<jdbc:script location="${int.drop.script}" />
|
||||
<jdbc:script location="${int.schema.script}" />
|
||||
</jdbc:initialize-database>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="DERBY" />
|
||||
|
||||
<jdbc:initialize-database data-source="dataSource" ignore-failures="DROPS">
|
||||
<jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
|
||||
<jdbc:script location="${int.drop.script}" />
|
||||
<jdbc:script location="${int.schema.script}" />
|
||||
</jdbc:initialize-database>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,10 +24,14 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.store.MessageGroup;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
@@ -38,6 +42,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
@@ -49,6 +61,21 @@ public class JdbcMessageStoreChannelTests {
|
||||
@Autowired
|
||||
private JdbcMessageStore messageStore;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("service-activator")
|
||||
private AbstractEndpoint serviceActivator;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
Service.reset(1);
|
||||
this.serviceActivator.start();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
this.serviceActivator.stop();
|
||||
}
|
||||
|
||||
@BeforeTransaction
|
||||
public void clear() {
|
||||
for (MessageGroup group : messageStore) {
|
||||
@@ -58,8 +85,7 @@ public class JdbcMessageStoreChannelTests {
|
||||
|
||||
@Test
|
||||
public void testSendAndActivate() throws Exception {
|
||||
Service.reset(1);
|
||||
input.send(new GenericMessage<String>("foo"));
|
||||
input.send(new GenericMessage<>("foo"));
|
||||
Service.await(10000);
|
||||
assertEquals(1, Service.messages.size());
|
||||
assertEquals(0, messageStore.getMessageGroup("JdbcMessageStoreChannelTests").size());
|
||||
@@ -67,9 +93,8 @@ public class JdbcMessageStoreChannelTests {
|
||||
|
||||
@Test
|
||||
public void testSendAndActivateWithRollback() throws Exception {
|
||||
Service.reset(1);
|
||||
Service.fail = true;
|
||||
input.send(new GenericMessage<String>("foo"));
|
||||
input.send(new GenericMessage<>("foo"));
|
||||
Service.await(10000);
|
||||
assertEquals(1, Service.messages.size());
|
||||
// After a rollback in the poller the message is still waiting to be delivered
|
||||
@@ -77,13 +102,12 @@ public class JdbcMessageStoreChannelTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Transactional(timeout = 1)
|
||||
public void testSendAndActivateTransactionalSend() throws Exception {
|
||||
Service.reset(1);
|
||||
input.send(new GenericMessage<String>("foo"));
|
||||
input.send(new GenericMessage<>("foo"));
|
||||
// This will time out because the transaction has not committed yet
|
||||
try {
|
||||
Service.await(10000);
|
||||
Service.await(10);
|
||||
fail("Expected timeout");
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
@@ -96,21 +120,28 @@ public class JdbcMessageStoreChannelTests {
|
||||
}
|
||||
|
||||
public static class Service {
|
||||
|
||||
private static boolean fail = false;
|
||||
|
||||
private static boolean alreadyFailed = false;
|
||||
private static List<String> messages = new CopyOnWriteArrayList<String>();
|
||||
|
||||
private static List<String> messages = new CopyOnWriteArrayList<>();
|
||||
|
||||
private static CountDownLatch latch = new CountDownLatch(0);
|
||||
|
||||
public static void reset(int count) {
|
||||
fail = false;
|
||||
alreadyFailed = false;
|
||||
messages.clear();
|
||||
latch = new CountDownLatch(count);
|
||||
}
|
||||
|
||||
public static void await(long timeout) throws InterruptedException {
|
||||
if (!latch.await(timeout, TimeUnit.MILLISECONDS)) {
|
||||
throw new IllegalStateException("Timed out waiting for message");
|
||||
}
|
||||
}
|
||||
|
||||
public String echo(String input) {
|
||||
if (!alreadyFailed) {
|
||||
messages.add(input);
|
||||
@@ -122,6 +153,7 @@ public class JdbcMessageStoreChannelTests {
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="DERBY"/>
|
||||
|
||||
<jdbc:initialize-database data-source="dataSource" ignore-failures="DROPS">
|
||||
<jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
|
||||
<jdbc:script location="${int.drop.script}"/>
|
||||
<jdbc:script location="${int.schema.script}"/>
|
||||
</jdbc:initialize-database>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
/> <property name="username" value="int" /> <property name="password" value="int"
|
||||
/> </bean> -->
|
||||
|
||||
<jdbc:initialize-database data-source="dataSource">
|
||||
<jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
|
||||
<jdbc:script location="classpath:org/springframework/integration/jdbc/schema-derby.sql" />
|
||||
</jdbc:initialize-database>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user