Skip to content

Commit

Permalink
Apply QA fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
skiddykong committed Dec 13, 2017
1 parent 892794d commit eba14c8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@

public class ReplayIntegrationIT {

private static final String SWARM_DEBUG_MODE = "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005";

private static final TestProperties TEST_PROPERTIES = new TestProperties("test.properties");
private static final String H2_DRIVER = "org.h2.Driver";

private static final UUID STREAM_ID = randomUUID();

Expand All @@ -51,12 +48,8 @@ public void setUpDB() throws Exception {

@Test
public void runReplayTool() throws Exception {
final String command = createCommandToExecuteReplay();

final UUID streamId = randomUUID();
insertEventLogData(streamId);
final boolean matches = runCommand(command);
assertTrue(matches);
insertEventLogData();
assertTrue(runCommand(createCommandToExecuteReplay()));
}

@After
Expand Down Expand Up @@ -99,13 +92,13 @@ private String createCommandToExecuteReplay() {
final String standaloneDSLocation = getResource("standalone-ds.xml");
final String listenerLocation = getResource("framework-tools-test-listener*.war");

String deubug = "";
String debug = "";

if (TEST_PROPERTIES.value("swarm.debug").equals("true")) {
deubug = SWARM_DEBUG_MODE;
if (TEST_PROPERTIES.value("swarm.debug.enabled").equals("true")) {
debug = TEST_PROPERTIES.value("swarm.debug.args");
}

final String command = commandFrom(deubug, replayJarLocation, standaloneDSLocation, listenerLocation);
final String command = commandFrom(debug, replayJarLocation, standaloneDSLocation, listenerLocation);

return command;
}
Expand All @@ -126,7 +119,7 @@ private static DataSource initDatabase(final String dbUrlPropertyName,
final String dbPasswordPropertyName,
final String... liquibaseChangeLogXmls) throws Exception {
final BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(H2_DRIVER);
dataSource.setDriverClassName(TEST_PROPERTIES.value("db.driver"));

dataSource.setUrl(TEST_PROPERTIES.value(dbUrlPropertyName));
dataSource.setUsername(TEST_PROPERTIES.value(dbUserNamePropertyName));
Expand Down Expand Up @@ -158,19 +151,21 @@ public boolean runCommand(final String command) throws Exception {
final BufferedReader reader =
new BufferedReader(new InputStreamReader(exec.getInputStream()));

final Pattern p = Pattern.compile(".*caught a fish.*", Pattern.MULTILINE | Pattern.DOTALL);
boolean matches = false;
String line = "";
while ((line = reader.readLine()) != null) {
Pattern p = Pattern.compile(".*caught a fish.*", Pattern.MULTILINE | Pattern.DOTALL);

if (p.matcher(line).matches()) {
matches = true;
}
System.out.println(line);
}
exec.destroyForcibly();
return matches;
}

private void insertEventLogData(final UUID streamId) throws SQLException, InvalidSequenceIdException {
private void insertEventLogData() throws SQLException, InvalidSequenceIdException {
EVENT_LOG_REPOSITORY.insert(eventLogFrom("framework.example-test"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,25 @@


import static java.lang.String.format;
import static java.sql.DriverManager.getDriver;
import static uk.gov.justice.services.test.utils.common.host.TestHostProvider.getHost;
import static uk.gov.justice.services.test.utils.common.reflection.ReflectionUtils.setField;

import uk.gov.justice.services.eventsourcing.repository.jdbc.AnsiSQLEventLogInsertionStrategy;
import uk.gov.justice.services.eventsourcing.repository.jdbc.eventlog.EventLogJdbcRepository;

import java.sql.SQLException;

import javax.sql.DataSource;

import org.apache.commons.dbcp2.BasicDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Standalone repository class to access event streams. To be used in integration testing
*/
public class TestEventLogRepository extends EventLogJdbcRepository {
private static final Logger LOGGER = LoggerFactory.getLogger(uk.gov.justice.services.test.utils.core.eventsource.TestEventLogRepository.class);
static final String SQL_FIND_ALL = "SELECT * FROM event_log";

private final DataSource datasource;

public TestEventLogRepository(final DataSource datasource) {
this.datasource = datasource;
this.logger = LOGGER;
setField(this, "eventLogInsertionStrategy", new AnsiSQLEventLogInsertionStrategy());
}

Expand All @@ -39,20 +31,6 @@ public TestEventLogRepository(final String url, final String username, final Str
dataSource.setUsername(username);
dataSource.setPassword(password);
this.datasource = dataSource;
this.logger = LOGGER;

}

public TestEventLogRepository(final String contextName) throws SQLException {
this(jdbcUrlFrom(contextName), contextName, contextName, getDriver(jdbcUrlFrom(contextName)).getClass().getName());
}

public static TestEventLogRepository forContext(final String contextName) {
try {
return new TestEventLogRepository(contextName);
} catch (SQLException e) {
throw new IllegalArgumentException(format("Error instantiating repository for context: %s", contextName), e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* accessor method
*/
public class TestProperties {
private static TestProperties instance;
private final Properties properties = new Properties();

public TestProperties(final String propertyFileName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ db.eventstore.url=jdbc:h2:tcp://localhost:8092/mem:eventstore;MVCC=true
db.eventstore.userName=sa
db.eventstore.password=sa

db.driver=org.h2.Driver

#Set to 'true' and remote connect on port 5005
swarm.debug=false
swarm.debug.enabled=false
swarm.debug.args=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005

0 comments on commit eba14c8

Please sign in to comment.