[SB3 Update] JDBC source and supplier updates
- Fix jdbc-source tests to use new Spring Integration Test Binder - Fix jdbc-supplier test to check root cause
This commit is contained in:
@@ -19,11 +19,13 @@
|
||||
<groupId>org.springframework.cloud.fn</groupId>
|
||||
<artifactId>jdbc-supplier</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-stream-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-stream</artifactId>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
<classifier>test-binder</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.cloud.stream.app.source.jdbc;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -26,31 +25,25 @@ import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Soby Chacko
|
||||
* @author Chris Bono
|
||||
*/
|
||||
@TestPropertySource(properties = "jdbc.supplier.query=select id, name from test order by id")
|
||||
class DefaultBehaviorTests extends JdbcSourceIntegrationTests {
|
||||
|
||||
@Test
|
||||
void testExtraction() throws Exception {
|
||||
Message<?> received = messageCollector.forChannel(output).poll(10, TimeUnit.SECONDS);
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getPayload().getClass()).isEqualTo(String.class);
|
||||
|
||||
Map<?, ?> payload = this.objectMapper.readValue((String) received.getPayload(), Map.class);
|
||||
|
||||
void testExtraction() {
|
||||
Message<?> received = receiveMessage(10_000);
|
||||
Map<?, ?> payload = extractPayload(received, Map.class);
|
||||
assertThat(payload.get("ID")).isEqualTo(1);
|
||||
received = messageCollector.forChannel(output).poll(10, TimeUnit.SECONDS);
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getPayload().getClass()).isEqualTo(String.class);
|
||||
|
||||
payload = this.objectMapper.readValue((String) received.getPayload(), Map.class);
|
||||
|
||||
received = receiveMessage(10_000);
|
||||
payload = extractPayload(received, Map.class);
|
||||
assertThat(payload.get("ID")).isEqualTo(2);
|
||||
received = messageCollector.forChannel(output).poll(10, TimeUnit.SECONDS);
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getPayload().getClass()).isEqualTo(String.class);
|
||||
|
||||
payload = this.objectMapper.readValue((String) received.getPayload(), Map.class);
|
||||
|
||||
received = receiveMessage(10_000);
|
||||
payload = extractPayload(received, Map.class);
|
||||
assertThat(payload.get("ID")).isEqualTo(3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,43 +16,74 @@
|
||||
|
||||
package org.springframework.cloud.stream.app.source.jdbc;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.fn.supplier.jdbc.JdbcSupplierConfiguration;
|
||||
import org.springframework.cloud.stream.test.binder.MessageCollector;
|
||||
import org.springframework.cloud.stream.binder.test.OutputDestination;
|
||||
import org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Soby Chacko
|
||||
* @author Artem Bilan
|
||||
* @author Chris Bono
|
||||
*/
|
||||
@SpringBootTest(properties = "spring.cloud.function.definition=jdbcSupplier")
|
||||
@DirtiesContext
|
||||
public class JdbcSourceIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
protected ObjectMapper objectMapper;
|
||||
|
||||
@Qualifier("jdbcSupplier-out-0")
|
||||
@Autowired
|
||||
protected MessageChannel output;
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Autowired
|
||||
protected JdbcOperations jdbcOperations;
|
||||
|
||||
@Autowired
|
||||
protected MessageCollector messageCollector;
|
||||
private OutputDestination outputDestination;
|
||||
|
||||
@SpringBootApplication
|
||||
@Import(JdbcSupplierConfiguration.class)
|
||||
public static class JdbcSourceTestApplication {
|
||||
@Nullable
|
||||
protected Message<?> receiveMessageMaybeNull(long timeoutMillis) {
|
||||
return this.outputDestination.receive(timeoutMillis, "jdbcSupplier-out-0");
|
||||
}
|
||||
|
||||
protected Message<?> receiveMessage(long timeoutMillis) {
|
||||
Message<?> received = this.outputDestination.receive(timeoutMillis, "jdbcSupplier-out-0");
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getPayload().getClass()).isEqualTo(byte[].class);
|
||||
return received;
|
||||
}
|
||||
|
||||
protected <T> T extractPayload(Message<?> message, Class<T> type) {
|
||||
try {
|
||||
return this.objectMapper.readValue(new String((byte[]) message.getPayload()), type);
|
||||
}
|
||||
catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected <T> T extractPayload(Message<?> message, JavaType type) {
|
||||
try {
|
||||
return this.objectMapper.readValue(new String((byte[]) message.getPayload()), type);
|
||||
}
|
||||
catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@SpringBootApplication
|
||||
@Import({ JdbcSupplierConfiguration.class, TestChannelBinderConfiguration.class })
|
||||
public static class JdbcSourceTestApplication {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.cloud.stream.app.source.jdbc;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.fasterxml.jackson.databind.type.CollectionLikeType;
|
||||
import com.fasterxml.jackson.databind.type.TypeFactory;
|
||||
@@ -32,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Soby Chacko
|
||||
* @author Artem Bilan
|
||||
* @author Chris Bono
|
||||
*/
|
||||
@TestPropertySource(properties = {
|
||||
"jdbc.supplier.query=select id, name, tag from test where tag is NULL order by id",
|
||||
@@ -41,22 +41,18 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class Select2PerPollNoSplitWithUpdateTests extends JdbcSourceIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testExtraction() throws Exception {
|
||||
Message<?> received = this.messageCollector.forChannel(this.output).poll(10, TimeUnit.SECONDS);
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getPayload().getClass()).isEqualTo(String.class);
|
||||
|
||||
public void testExtraction() {
|
||||
CollectionLikeType valueType = TypeFactory.defaultInstance()
|
||||
.constructCollectionLikeType(List.class, Map.class);
|
||||
|
||||
List<Map<?, ?>> payload = this.objectMapper.readValue((String) received.getPayload(), valueType);
|
||||
|
||||
Message<?> received = receiveMessage(10_000);
|
||||
List<Map<?, ?>> payload = extractPayload(received, valueType);
|
||||
assertThat(payload.size()).isEqualTo(2);
|
||||
assertThat(payload.get(0).get("ID")).isEqualTo(1);
|
||||
assertThat(payload.get(1).get("ID")).isEqualTo(2);
|
||||
received = this.messageCollector.forChannel(this.output).poll(10, TimeUnit.SECONDS);
|
||||
assertThat(received).isNotNull();
|
||||
payload = this.objectMapper.readValue((String) received.getPayload(), valueType);
|
||||
|
||||
received = receiveMessage(10_000);
|
||||
payload = extractPayload(received, valueType);
|
||||
assertThat(payload.size()).isEqualTo(1);
|
||||
assertThat(payload.get(0).get("ID")).isEqualTo(3);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.cloud.stream.app.source.jdbc;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.fasterxml.jackson.databind.type.CollectionLikeType;
|
||||
import com.fasterxml.jackson.databind.type.TypeFactory;
|
||||
@@ -32,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Soby Chacko
|
||||
* @author Artem Bilan
|
||||
* @author Chris Bono
|
||||
*/
|
||||
@TestPropertySource(properties = {
|
||||
"jdbc.supplier.query=select id, name, tag from test where tag is NULL order by id",
|
||||
@@ -40,16 +40,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class SelectAllNoSplitTests extends JdbcSourceIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testExtraction() throws Exception {
|
||||
Message<?> received = messageCollector.forChannel(output).poll(10, TimeUnit.SECONDS);
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getPayload().getClass()).isEqualTo(String.class);
|
||||
|
||||
public void testExtraction() {
|
||||
CollectionLikeType valueType = TypeFactory.defaultInstance()
|
||||
.constructCollectionLikeType(List.class, Map.class);
|
||||
|
||||
List<Map<?, ?>> payload = this.objectMapper.readValue((String) received.getPayload(), valueType);
|
||||
|
||||
Message<?> received = receiveMessage(10_000);
|
||||
List<Map<?, ?>> payload = extractPayload(received, valueType);
|
||||
assertThat(payload.size()).isEqualTo(3);
|
||||
assertThat(payload.get(0).get("ID")).isEqualTo(1);
|
||||
assertThat(payload.get(2).get("NAME")).isEqualTo("John");
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.cloud.stream.app.source.jdbc;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -26,32 +25,29 @@ import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Soby Chacko
|
||||
* @author Chris Bono
|
||||
*/
|
||||
@TestPropertySource(properties = {"jdbc.supplier.query=select id, name from test order by id", "spring.cloud.stream.poller.fixedDelay=60000"})
|
||||
public class SelectAllWithDelayTests extends JdbcSourceIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testExtraction() throws Exception {
|
||||
Message<?> received = messageCollector.forChannel(output).poll(10, TimeUnit.SECONDS);
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getPayload().getClass()).isEqualTo(String.class);
|
||||
|
||||
Map<?, ?> payload = this.objectMapper.readValue((String) received.getPayload(), Map.class);
|
||||
|
||||
public void testExtraction() {
|
||||
Message<?> received = receiveMessage(10_000);
|
||||
Map<?, ?> payload = extractPayload(received, Map.class);
|
||||
assertThat(payload.get("ID")).isEqualTo(1);
|
||||
received = messageCollector.forChannel(output).poll(10, TimeUnit.SECONDS);
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getPayload().getClass()).isEqualTo(String.class);
|
||||
|
||||
payload = this.objectMapper.readValue((String) received.getPayload(), Map.class);
|
||||
received = receiveMessage(10_000);
|
||||
payload = extractPayload(received, Map.class);
|
||||
assertThat(payload.get("ID")).isEqualTo(2);
|
||||
received = messageCollector.forChannel(output).poll(10, TimeUnit.SECONDS);
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getPayload().getClass()).isEqualTo(String.class);
|
||||
|
||||
payload = this.objectMapper.readValue((String) received.getPayload(), Map.class);
|
||||
received = receiveMessage(10_000);
|
||||
payload = extractPayload(received, Map.class);
|
||||
assertThat(payload.get("ID")).isEqualTo(3);
|
||||
|
||||
// should not wrap around to the beginning since delay is 60
|
||||
received = messageCollector.forChannel(output).poll(1, TimeUnit.SECONDS);
|
||||
received = receiveMessageMaybeNull(10_000);
|
||||
assertThat(received).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.cloud.stream.app.source.jdbc;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -26,38 +25,33 @@ import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@TestPropertySource(properties = {"jdbc.supplier.query=select id, name from test order by id", "spring.cloud.stream.poller.fixedDelay=1"})
|
||||
/**
|
||||
* @author Soby Chacko
|
||||
* @author Chris Bono
|
||||
*/
|
||||
@TestPropertySource(properties = {
|
||||
"jdbc.supplier.query=select id, name from test order by id",
|
||||
"spring.cloud.stream.poller.fixedDelay=1"
|
||||
})
|
||||
public class SelectAllWithMinDelayTests extends JdbcSourceIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testExtraction() throws Exception {
|
||||
Message<?> received = messageCollector.forChannel(output).poll(10, TimeUnit.SECONDS);
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getPayload().getClass()).isEqualTo(String.class);
|
||||
|
||||
Map<?, ?> payload = this.objectMapper.readValue((String) received.getPayload(), Map.class);
|
||||
|
||||
public void testExtraction() {
|
||||
Message<?> received = receiveMessage(10_000);
|
||||
Map<?, ?> payload = extractPayload(received, Map.class);
|
||||
assertThat(payload.get("ID")).isEqualTo(1);
|
||||
received = messageCollector.forChannel(output).poll(10, TimeUnit.SECONDS);
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getPayload().getClass()).isEqualTo(String.class);
|
||||
payload = this.objectMapper.readValue((String) received.getPayload(), Map.class);
|
||||
|
||||
received = receiveMessage(10_000);
|
||||
payload = extractPayload(received, Map.class);
|
||||
assertThat(payload.get("ID")).isEqualTo(2);
|
||||
received = messageCollector.forChannel(output).poll(10, TimeUnit.SECONDS);
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getPayload().getClass()).isEqualTo(String.class);
|
||||
|
||||
payload = this.objectMapper.readValue((String) received.getPayload(), Map.class);
|
||||
|
||||
received = receiveMessage(10_000);
|
||||
payload = extractPayload(received, Map.class);
|
||||
assertThat(payload.get("ID")).isEqualTo(3);
|
||||
|
||||
// should wrap around to the beginning
|
||||
received = messageCollector.forChannel(output).poll(2, TimeUnit.SECONDS);
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getPayload().getClass()).isEqualTo(String.class);
|
||||
|
||||
payload = this.objectMapper.readValue((String) received.getPayload(), Map.class);
|
||||
|
||||
received = receiveMessage(10_000);
|
||||
payload = extractPayload(received, Map.class);
|
||||
assertThat(payload.get("ID")).isEqualTo(1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user