Skip to content

Commit

Permalink
Drop H2 schema before JDBC tests
Browse files Browse the repository at this point in the history
  • Loading branch information
artembilan committed Apr 8, 2019
1 parent 33883be commit a8a44ab
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
http://www.springframework.org/schema/integration/jdbc https://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd">

<jdbc:embedded-database id="dataSource" type="H2">
<jdbc:script location="org/springframework/integration/jdbc/schema-drop-h2.sql"/>
<jdbc:script location="org/springframework/integration/jdbc/schema-h2.sql"/>
</jdbc:embedded-database>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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.
Expand All @@ -18,8 +18,6 @@

import static org.junit.Assert.assertEquals;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.junit.After;
Expand All @@ -28,28 +26,32 @@
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import org.springframework.integration.support.MessageBuilder;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;

/**
* @author Gunnar Hillert
* @author Artem Bilan
*/
public class JdbcMessageStoreRegionTests {

private static EmbeddedDatabase dataSource;

private JdbcTemplate jdbcTemplate;

private JdbcMessageStore messageStore1;

private JdbcMessageStore messageStore2;

@BeforeClass
public static void setupDatabase() {
dataSource = new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)
.addScript("classpath:/org/springframework/integration/jdbc/schema-drop-h2.sql")
.addScript("classpath:/org/springframework/integration/jdbc/schema-h2.sql")
.build();
}
Expand Down Expand Up @@ -77,7 +79,7 @@ public void afterTest() {
}

@Test
public void testVerifyMessageCount() throws Exception {
public void testVerifyMessageCount() {

messageStore1.addMessage(MessageBuilder.withPayload("payload1").build());
messageStore1.addMessage(MessageBuilder.withPayload("payload2").build());
Expand All @@ -91,7 +93,7 @@ public void testVerifyMessageCount() throws Exception {
}

@Test
public void testInsertNullRegion() throws Exception {
public void testInsertNullRegion() {

try {
messageStore1.setRegion(null);
Expand All @@ -105,7 +107,7 @@ public void testInsertNullRegion() throws Exception {
}

@Test
public void testVerifyMessageGroupCount() throws Exception {
public void testVerifyMessageGroupCount() {

messageStore1.addMessageToGroup("group1", MessageBuilder.withPayload("payload1").build());
messageStore1.addMessageToGroup("group2", MessageBuilder.withPayload("payload2").build());
Expand All @@ -124,38 +126,28 @@ public void testVerifyMessageGroupCount() throws Exception {
}

@Test
public void testRegionSetToMessageGroup() throws Exception {
public void testRegionSetToMessageGroup() {

messageStore1.addMessageToGroup("group1", MessageBuilder.withPayload("payload1").build());

List<String> regions = jdbcTemplate.query("Select * from INT_MESSAGE_GROUP where REGION = 'region1'", new RowMapper<String>() {

public String mapRow(ResultSet rs, int rowNum) throws SQLException {
return rs.getString("REGION");
}

});
List<String> regions = jdbcTemplate.query("Select * from INT_MESSAGE_GROUP where REGION = 'region1'",
(rs, rowNum) -> rs.getString("REGION"));

assertEquals(1, regions.size());
assertEquals("region1", regions.get(0));

messageStore2.addMessageToGroup("group1", MessageBuilder.withPayload("payload1").build());

List<String> regions2 = jdbcTemplate.query("Select * from INT_MESSAGE_GROUP where REGION = 'region2'", new RowMapper<String>() {

public String mapRow(ResultSet rs, int rowNum) throws SQLException {
return rs.getString("REGION");
}

});
List<String> regions2 = jdbcTemplate.query("Select * from INT_MESSAGE_GROUP where REGION = 'region2'",
(rs, rowNum) -> rs.getString("REGION"));

assertEquals(1, regions2.size());
assertEquals("region2", regions2.get(0));

}

@Test
public void testRemoveMessageGroup() throws Exception {
public void testRemoveMessageGroup() {

messageStore1.addMessageToGroup("group1", MessageBuilder.withPayload("payload1").build());
messageStore1.addMessageToGroup("group2", MessageBuilder.withPayload("payload2").build());
Expand All @@ -169,4 +161,5 @@ public void testRemoveMessageGroup() throws Exception {
assertEquals(2, messageStore2.getMessageGroupCount());

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class JdbcLockRegistryLeaderInitiatorTests {
public static void init() {
dataSource = new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)
.addScript("classpath:/org/springframework/integration/jdbc/schema-drop-h2.sql")
.addScript("classpath:/org/springframework/integration/jdbc/schema-h2.sql")
.build();
}
Expand All @@ -66,7 +67,7 @@ public static void destroy() {
public void testDistributedLeaderElection() throws Exception {
CountDownLatch granted = new CountDownLatch(1);
CountingPublisher countingPublisher = new CountingPublisher(granted);
List<LockRegistryLeaderInitiator> initiators = new ArrayList<LockRegistryLeaderInitiator>();
List<LockRegistryLeaderInitiator> initiators = new ArrayList<>();
for (int i = 0; i < 2; i++) {
DefaultLockRepository lockRepository = new DefaultLockRepository(dataSource);
lockRepository.afterPropertiesSet();
Expand Down

0 comments on commit a8a44ab

Please sign in to comment.