Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Commit

Permalink
Update framework version to 5.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
mapingo committed Nov 22, 2018
1 parent 9c36ccc commit aace6d6
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 40 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to

## Unreleased

## [3.0.0] - 2018-11-22

### Changed
- Update to framework version 5.0.4
- Use event-store version 1.0.4

## [2.2.0] - 2018-11-05

## Changed
### Changed
- Update utilities to version 1.16.0

## Removed
### Removed
- LoggerProducer and InitialContextProducer

## [2.1.0]
Expand Down
2 changes: 1 addition & 1 deletion job-manager-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<dependency>
<groupId>uk.gov.justice.services</groupId>
<artifactId>test-utils-common</artifactId>
<version>${framework-version}</version>
<version>${framework.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package uk.gov.moj.cpp.jobmanager.it;

import static java.lang.Thread.sleep;
import static java.util.stream.IntStream.range;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static uk.gov.justice.services.test.utils.core.reflection.ReflectionUtil.setField;

import uk.gov.justice.services.cdi.InitialContextProducer;
import uk.gov.justice.services.cdi.LoggerProducer;
Expand All @@ -19,7 +22,6 @@
import uk.gov.justice.services.messaging.JsonObjectEnvelopeConverter;
import uk.gov.justice.services.messaging.logging.DefaultTraceLogger;
import uk.gov.justice.services.test.utils.common.envelope.EnvelopeRecordingInterceptor;
import uk.gov.justice.services.test.utils.common.reflection.ReflectionUtils;
import uk.gov.moj.cpp.jobmanager.it.util.OpenEjbConfigurationBuilder;
import uk.gov.moj.cpp.jobmanager.it.util.OpenEjbJobJdbcRepository;
import uk.gov.moj.cpp.jobstore.api.ExecutionService;
Expand All @@ -44,7 +46,6 @@
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import javax.annotation.Resource;
Expand All @@ -68,7 +69,6 @@
import org.apache.openejb.testing.Classes;
import org.apache.openejb.testing.Configuration;
import org.apache.openejb.testing.Module;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -137,10 +137,10 @@ public WebApp war() {

@Before
public void setup() throws Exception {
InitialContext initialContext = new InitialContext();
final InitialContext initialContext = new InitialContext();
initialContext.bind("java:/app/JobSchedulerIT/DS.jobstore", dataSource);
initEventDatabase();
ReflectionUtils.setField(jobService, "jobCount", "10");
setField(jobService, "jobCount", "10");
}

@Configuration
Expand All @@ -162,7 +162,7 @@ public void initEventDatabase() throws Exception {

eventStoreLiquibase.update("");

ReflectionUtils.setField(jobService, "jobRepository", testJobJdbcRepository);
setField(jobService, "jobRepository", testJobJdbcRepository);
}

@Test
Expand All @@ -173,15 +173,19 @@ public void shouldNotPerformDuplicateJobUpdates() throws Exception {
userTransaction.commit();

userTransaction.begin();

final CyclicBarrier gate = new CyclicBarrier(4);
IntStream.range(0, 3)

range(0, 3)
.mapToObj(threadNo -> getThreadCurrentImpl(gate))
.forEach(t -> t.start());
.forEach(Thread::start);

gate.await();
Thread.sleep(3000);

sleep(3000);
userTransaction.commit();

assertThat(testJobJdbcRepository.jobsNotProcessed(), CoreMatchers.is(20));
assertThat(testJobJdbcRepository.jobsNotProcessed(), is(20));
}


Expand All @@ -192,7 +196,7 @@ private Thread getThreadCurrentImpl(final CyclicBarrier gate) {
userTransaction.begin();

jobScheduler.fetchUnassignedJobs();
assertExpectedJobAssigments();
assertExpectedJobAssignments();

userTransaction.commit();

Expand All @@ -204,10 +208,10 @@ private Thread getThreadCurrentImpl(final CyclicBarrier gate) {
});
}

private void assertExpectedJobAssigments() throws SQLException {
private void assertExpectedJobAssignments() throws SQLException {
final Stream<Job> jobStream = testJobJdbcRepository.getProcessedRecords();
final Map<UUID, List<Job>> jobByWorkerIdMap = jobStream.collect(Collectors.groupingBy(x -> x.getWorkerId().get()));
final Set<UUID> jobs = new HashSet();
final Set<UUID> jobs = new HashSet<>();
final List<UUID> duplicates = new ArrayList<>();

testJobJdbcRepository.collectDuplicates(jobs, duplicates, jobByWorkerIdMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
import static java.time.temporal.ChronoUnit.MINUTES;
import static java.util.Optional.of;
import static java.util.UUID.randomUUID;
import static java.util.stream.IntStream.range;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static uk.gov.justice.services.test.utils.core.reflection.ReflectionUtil.setField;

import uk.gov.justice.services.cdi.InitialContextProducer;
import uk.gov.justice.services.cdi.LoggerProducer;
import uk.gov.justice.services.common.configuration.GlobalValueProducer;
import uk.gov.justice.services.common.configuration.JndiBasedServiceContextNameProvider;
import uk.gov.justice.services.common.configuration.ValueProducer;
import uk.gov.justice.services.jdbc.persistence.JdbcRepositoryHelper;
import uk.gov.justice.services.test.utils.common.reflection.ReflectionUtils;
import uk.gov.justice.services.test.utils.core.messaging.Poller;
import uk.gov.moj.cpp.jobmanager.it.util.OpenEjbConfigurationBuilder;
import uk.gov.moj.cpp.jobmanager.it.util.OpenEjbJobJdbcRepository;
Expand All @@ -36,7 +37,6 @@
import java.util.UUID;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import javax.annotation.Resource;
Expand Down Expand Up @@ -106,10 +106,10 @@ public WebApp war() {

@Before
public void setup() throws Exception {
InitialContext initialContext = new InitialContext();
final InitialContext initialContext = new InitialContext();
initialContext.bind("java:/app/JobServiceIT/DS.jobstore", dataSource);
initEventDatabase();
ReflectionUtils.setField(jobService, "jobCount", "10");
setField(jobService, "jobCount", "10");
}

@Configuration
Expand All @@ -131,7 +131,7 @@ public void initEventDatabase() throws Exception {

eventStoreLiquibase.update("");

ReflectionUtils.setField(jobService, "jobRepository", testJobJdbcRepository);
setField(jobService, "jobRepository", testJobJdbcRepository);
}

@Test
Expand Down Expand Up @@ -185,9 +185,11 @@ public void shouldNotPerformDuplicateJobUpdates() throws Exception {
userTransaction.commit();

final CyclicBarrier gate = new CyclicBarrier(21);
IntStream.range(0, 20)

range(0, 20)
.mapToObj(threadNo -> getThreadCurrentImpl(gate))
.forEach(t -> t.start());
.forEach(Thread::start);

gate.await();

detectDuplicates();
Expand Down Expand Up @@ -228,7 +230,7 @@ private synchronized void collectInfo(final UUID workerId) throws SQLException {


private void detectDuplicates() throws InterruptedException {
final Set<UUID> jobs = new HashSet();
final Set<UUID> jobs = new HashSet<>();
final List<UUID> duplicates = new ArrayList<>();

final Poller poller = new Poller(10, 100L);
Expand Down
6 changes: 3 additions & 3 deletions jobstore-persistence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<dependency>
<groupId>uk.gov.justice.services</groupId>
<artifactId>persistence-jdbc</artifactId>
<version>${framework-version}</version>
<version>${framework.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.utils</groupId>
Expand All @@ -48,9 +48,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>test-utils-persistence</artifactId>
<version>${framework-version}</version>
<version>${event-store.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package uk.gov.moj.cpp.jobstore.persistence;

import static java.lang.String.format;
import static java.time.ZonedDateTime.now;
import static java.util.Optional.empty;
import static java.util.Optional.of;
Expand All @@ -20,7 +19,6 @@
import uk.gov.justice.services.jdbc.persistence.JdbcRepositoryHelper;
import uk.gov.justice.services.jdbc.persistence.PreparedStatementWrapper;
import uk.gov.justice.services.test.utils.core.messaging.Poller;
import uk.gov.justice.services.test.utils.persistence.TestDataSourceFactory;

import java.io.StringReader;
import java.sql.ResultSet;
Expand All @@ -36,19 +34,18 @@

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;

public class JobJdbcRepositoryTest {

private static final String LIQUIBASE_JOB_STORE_DB_CHANGELOG_XML = "liquibase/jobstore-db-changelog.xml";

private final JobJdbcRepository jdbcRepository = new JobJdbcRepository();

private static final String JOBS_COUNT = "SELECT COUNT(*) FROM job";

private static final String JOB_DATA_JSON = "{\"some\": \"json\"}";

private final JobJdbcRepository jdbcRepository = new JobJdbcRepository();

@Before
public void initialize() {
try {
Expand All @@ -70,7 +67,7 @@ private void checkIfReady() {
try {
jdbcRepository.dataSource.getConnection().prepareStatement(JOBS_COUNT).execute();
return of("Success");
} catch (SQLException e) {
} catch (final SQLException e) {
e.printStackTrace();
fail("Job store construction failed");
return empty();
Expand All @@ -94,7 +91,6 @@ public void shouldAddEmailNotificationWithMandatoryDataOnly() {
assertThat(jobsCount, is(1));
}


@Test
public void shouldAddEmailNotificationWithMandatoryAndOptionalData() {
final UUID jobId1 = randomUUID();
Expand Down Expand Up @@ -163,8 +159,9 @@ public void shouldLockJobsToWorker() throws SQLException {
assertThat(jobs.size(), is(4));
}

@Ignore("TODO: This test is flip flopping when run with all the tests, needs to be investigated")
@Test
public void shouldFindLockedJobsToWorker() {
public void shouldFindLockedJobsToWorker() throws Exception {
final UUID jobId = randomUUID();
final Optional<UUID> worker = of(randomUUID());

Expand Down Expand Up @@ -310,7 +307,7 @@ private int jobsCount() {
jobsCount = rs.getInt(1);
}
} catch (SQLException e) {
throw new JdbcRepositoryException(format("Exception while retrieving jobs count"), e);
throw new JdbcRepositoryException("Exception while retrieving jobs count", e);
}
return jobsCount;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package uk.gov.moj.cpp.jobstore.persistence;

import java.sql.SQLException;
import java.util.Properties;

import javax.naming.Context;

import liquibase.Liquibase;
import liquibase.database.jvm.JdbcConnection;
import liquibase.exception.LiquibaseException;
import liquibase.resource.ClassLoaderResourceAccessor;
import org.h2.jdbcx.JdbcDataSource;

public class TestDataSourceFactory {

private static final String H2_CONFIG_URL = "jdbc:h2:mem:test;MV_STORE=FALSE;MVCC=FALSE;LOCK_MODE=3;DB_CLOSE_ON_EXIT=TRUE";
private JdbcDataSource dataSource;
private final String liquibaseLocation;

public TestDataSourceFactory(final String liquibaseLocation) {
this.liquibaseLocation = liquibaseLocation;
}

public JdbcDataSource createDataSource() throws LiquibaseException, SQLException {

return createDataSource(H2_CONFIG_URL);
}

public JdbcDataSource createDataSource(String h2ConfigUrl) throws LiquibaseException, SQLException {

return createDataSource(h2ConfigUrl, defaultSystemProperties(), "sa", "sa");
}

private Properties defaultSystemProperties() {
final Properties properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
properties.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");
return properties;
}

public JdbcDataSource createDataSource(final String h2ConfigUrl, final Properties systemProperties, String userName, String password) throws LiquibaseException, SQLException {

System.getProperties().putAll(systemProperties);

dataSource = new JdbcDataSource();
dataSource.setURL(h2ConfigUrl);
dataSource.setUser(userName);
dataSource.setPassword(password);


initDatabase();
return dataSource;
}

private void initDatabase() throws LiquibaseException, SQLException {
final Liquibase liquibase = new Liquibase(liquibaseLocation,
new ClassLoaderResourceAccessor(), new JdbcConnection(dataSource.getConnection()));
liquibase.dropAll();
liquibase.update("");
}
}
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
<properties>
<cpp.repo.name>job-manager</cpp.repo.name>
<common-bom.version>1.28.0</common-bom.version>
<test-utils.version>1.18.0</test-utils.version>
<utilities.version>1.16.0</utilities.version>
<framework-version>4.4.2</framework-version>
<test-utils.version>1.18.1</test-utils.version>
<utilities.version>1.16.1</utilities.version>
<framework.version>5.0.4</framework.version>
<event-store.version>1.0.4</event-store.version>
</properties>

<build>
Expand Down

0 comments on commit aace6d6

Please sign in to comment.