Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
valb3r committed Feb 8, 2020
2 parents 6c9c6f6 + 946dfd3 commit b0f424a
Show file tree
Hide file tree
Showing 20 changed files with 420 additions and 26 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew clean build
run: ./gradlew clean build jacocoTestReport
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: unittests
fail_ci_if_error: true
- name: Send artifacts to BinTray
if: startsWith(github.ref, 'refs/tags/v')
env:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public class SimpleJobService {
log.info("STEP ONE!");
return null;
}).build())
.start(stepBuilderFactory.get("TWO").tasklet((a, b) -> {
.next(stepBuilderFactory.get("TWO").tasklet((a, b) -> {
log.info("STEP TWO!");
result.set("Step TWO DONE");
return null;
Expand Down
19 changes: 18 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ buildscript {
}
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'java'

idea {
project {
Expand All @@ -46,8 +46,25 @@ idea {
}
}

allprojects {
apply plugin: 'java'
apply plugin: 'jacoco'

jacoco {
toolVersion = '0.8.5'
}
}

subprojects {
tasks.withType(Test) {
useJUnitPlatform()
}

jacocoTestReport {
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void runSimpleJob() {
log.info("STEP ONE!");
return null;
}).build())
.start(stepBuilderFactory.get("TWO").tasklet((a, b) -> {
.next(stepBuilderFactory.get("TWO").tasklet((a, b) -> {
log.info("STEP TWO!");
result.set("Step TWO DONE");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import org.springframework.batch.core.repository.dao.JobInstanceDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import static org.assertj.core.api.Assertions.assertThat;

@ActiveProfiles("test")
@SpringBootTest
class SimpleJobServiceTest {

Expand Down
6 changes: 0 additions & 6 deletions examples/src/test/resources/application-test.yml

This file was deleted.

2 changes: 2 additions & 0 deletions lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lombok.anyconstructor.addconstructorproperties = true
lombok.addLombokGeneratedAnnotation = true
9 changes: 9 additions & 0 deletions neo4j-adapter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@ dependencies {
annotationProcessor "org.mapstruct:mapstruct-processor:${versions.mapstruct}"
compile "org.slf4j:slf4j-api:${versions.slf4j}"

// Tests:

runtime "org.neo4j:neo4j:${versions.ogmCore}"

testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile "org.junit.jupiter:junit-jupiter-engine:${versions.junit}"
testCompile "org.neo4j:neo4j-ogm-embedded-driver:${versions.neo4jEmbedded}"

testCompileOnly "org.projectlombok:lombok:${versions.lombok}"
testAnnotationProcessor "org.projectlombok:lombok:${versions.lombok}"
}

bootJar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void updateJobExecution(JobExecution jobExecution) {
@Override
@Transactional
public List<JobExecution> findJobExecutions(JobInstance jobInstance) {
return jobExecs.findAllByJobInstanceId(jobInstance.getId())
return jobExecs.findByJobInstanceId(jobInstance.getId())
.stream()
.map(it -> Neo4jJobExecution.MAP.map(it, new CycleAvoidingMappingContext()))
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ public List<JobInstance> findJobInstancesByName(String jobName, int start, int c

@Override
public int getJobInstanceCount(String jobName) throws NoSuchJobException {
return jobInstances.countAllByJobName();
return jobInstances.countAllByJobName(jobName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public StepExecution getStepExecution(JobExecution jobExecution, Long stepExecut
}

@Override
@Transactional
public StepExecution getLastStepExecution(JobInstance jobInstance, String stepName) {
List<Neo4jStepExecution> executions = stepExecs.findLastStepExecution(jobInstance.getInstanceId(), stepName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
@Repository
public interface Neo4jJobExecutionRepository extends CrudRepository<Neo4jJobExecution, Long> {

List<Neo4jJobExecution> findAllByJobInstanceId(long instanceId);
@Query("MATCH (s:Neo4jStepExecution)-[r1:PARENT]->(e:Neo4jJobExecution)-[r2:PARENT]->(i:Neo4jJobInstance) WHERE id(i) = $instanceId RETURN e, i, s, r1, r2")
List<Neo4jJobExecution> findByJobInstanceId(long instanceId);

@Query("MATCH (e:Neo4jJobExecution)-[:PARENT]->(i:Neo4jJobInstance) WHERE i.id = $instanceId RETURN e " +
"ORDER BY e.createTime LIMIT 1")
@Query("MATCH (s:Neo4jStepExecution)-[r1:PARENT]->(e:Neo4jJobExecution)-[r2:PARENT]->(i:Neo4jJobInstance) WHERE id(i) = $instanceId RETURN e, i, s, r1, r2 " +
"ORDER BY e.createTime DESC LIMIT 1")
Optional<Neo4jJobExecution> findLatestExecution(@Param("instanceId") long instanceId);

@Query("MATCH (e:Neo4jJobExecution)-[:PARENT]->(i:Neo4jJobInstance) " +
"WHERE i.jobName = $name AND e.startTime IS NOT NULL AND e.endTime IS NULL RETURN e " +
"ORDER BY e.id DESC")
@Query("MATCH (s:Neo4jStepExecution)-[r1:PARENT]->(e:Neo4jJobExecution)-[r2:PARENT]->(i:Neo4jJobInstance) " +
"WHERE i.jobName = $name AND e.startTime IS NOT NULL AND e.endTime IS NULL RETURN e, i, s, r1, r2 " +
"ORDER BY id(e) DESC")
List<Neo4jJobExecution> findRunningJobExecutions(@Param("name") String jobName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface Neo4jJobInstanceRepository extends CrudRepository<Neo4jJobInsta
@Query("MATCH (i:Neo4jJobInstance) WHERE i.jobName = $jobName AND i.jobKey = $jobKey RETURN i")
Optional<Neo4jJobInstance> findBy(@Param("jobName") String jobName, @Param("jobKey") String jobKey);

@Query("MATCH (e:Neo4jJobExecution)-[:" + PARENT + "]->(i:Neo4jJobInstance) WHERE e.id = $jobExecutionId RETURN i")
@Query("MATCH (e:Neo4jJobExecution)-[r:" + PARENT + "]->(i:Neo4jJobInstance) WHERE id(e) = $jobExecutionId RETURN i, e, r")
Optional<Neo4jJobInstance> findForExecution(@Param("jobExecutionId") long jobExecutionId);

@Query("MATCH (i:Neo4jJobInstance) WHERE i.jobName = $jobName RETURN i " +
Expand All @@ -42,5 +42,5 @@ List<Neo4jJobInstance> findByLikeJobName(
"ORDER BY i.jobName DESC")
List<String> allNames();

int countAllByJobName();
int countAllByJobName(String jobName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
@Repository
public interface Neo4jStepExecutionRepository extends CrudRepository<Neo4jStepExecution, Long> {

@Query("MATCH (s:Neo4jStepExecution)-[:PARENT]->(e:Neo4jJobExecution) " +
"WHERE e.id = $jobExecId AND s.id = $stepExecId " +
"RETURN s")
@Query("MATCH (s:Neo4jStepExecution)-[r:PARENT]->(e:Neo4jJobExecution) " +
"WHERE id(e) = $jobExecId AND id(s) = $stepExecId " +
"RETURN s, e, r")
Optional<Neo4jStepExecution> findBy(
@Param("jobExecId") long jobExecId,
@Param("stepExecId") long stepExecId
);

@Query("MATCH (s:Neo4jStepExecution)-[:PARENT]->(e:Neo4jJobExecution)-[:PARENT]->(j:Neo4jJobInstance) " +
"WHERE j.id = $jobExecInstanceId AND s.stepName = $stepName " +
"RETURN s ORDER BY s.startTime DESC, s.id DESC")
@Query("MATCH (s:Neo4jStepExecution)-[r1:PARENT]->(e:Neo4jJobExecution)-[r2:PARENT]->(j:Neo4jJobInstance) " +
"WHERE id(j) = $jobExecInstanceId AND s.stepName = $stepName " +
"RETURN s, e, j, r1, r2 ORDER BY s.startTime DESC, id(s) DESC")
List<Neo4jStepExecution> findLastStepExecution(
@Param("jobExecInstanceId") long jobExecInstanceId,
@Param("stepName") String stepName
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.github.valb3r.springbatch.adapters.neo4j.dao;

import com.github.valb3r.springbatch.adapters.neo4j.dao.testconfig.TestApplication;
import org.junit.jupiter.api.AfterEach;
import org.neo4j.ogm.session.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import java.util.Collections;

@ActiveProfiles("test")
@SpringBootTest(classes = TestApplication.class)
public abstract class BaseTest {

@Autowired
private SessionFactory factory;

@AfterEach
void dropDatabase() {
factory.openSession().query("MATCH (n) DETACH DELETE n", Collections.emptyMap());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package com.github.valb3r.springbatch.adapters.neo4j.dao;

import com.github.valb3r.springbatch.adapters.neo4j.dao.testconfig.JobProvider;
import lombok.val;
import org.junit.jupiter.api.Test;
import org.springframework.batch.core.repository.dao.JobExecutionDao;
import org.springframework.batch.core.repository.dao.JobInstanceDao;
import org.springframework.batch.core.repository.dao.StepExecutionDao;
import org.springframework.beans.factory.annotation.Autowired;

import static com.github.valb3r.springbatch.adapters.neo4j.dao.testconfig.JobProvider.CHUNK_ONE;
import static com.github.valb3r.springbatch.adapters.neo4j.dao.testconfig.JobProvider.CHUNK_TWO;
import static com.github.valb3r.springbatch.adapters.neo4j.dao.testconfig.JobProvider.DONE;
import static com.github.valb3r.springbatch.adapters.neo4j.dao.testconfig.JobProvider.ONE_STEP_TASKLET;
import static com.github.valb3r.springbatch.adapters.neo4j.dao.testconfig.JobProvider.READER_WRITER;
import static com.github.valb3r.springbatch.adapters.neo4j.dao.testconfig.JobProvider.READS_ONE;
import static com.github.valb3r.springbatch.adapters.neo4j.dao.testconfig.JobProvider.READS_TWO;
import static com.github.valb3r.springbatch.adapters.neo4j.dao.testconfig.JobProvider.STEP_ONE;
import static com.github.valb3r.springbatch.adapters.neo4j.dao.testconfig.JobProvider.STEP_TWO;
import static com.github.valb3r.springbatch.adapters.neo4j.dao.testconfig.JobProvider.TWO_STEPS_TASKLET;
import static org.assertj.core.api.Assertions.assertThat;

class SimpleExecutionFlowValidationTest extends BaseTest {

@Autowired
private JobProvider provider;

@Autowired
private JobInstanceDao instanceDao;

@Autowired
private JobExecutionDao executionDao;

@Autowired
private StepExecutionDao stepExecutionDao;

@Test
void runOneStepTasklet() {
val job = provider.oneStepTaskletJobEmptyParams();
job.exec();

assertThat(job.getStats().getResult()).hasValue(DONE);
assertThat(job.getStats().getTaskletsDone()).hasValue(1);
assertThat(instanceDao.getJobNames()).containsExactly(ONE_STEP_TASKLET);
assertThat(executionDao.findJobExecutions(job.getInstance())).hasSize(1);
assertThat(stepExecutionDao.getLastStepExecution(job.getInstance(), STEP_ONE)).isNotNull();
assertThat(stepExecutionDao.getLastStepExecution(job.getInstance(), STEP_TWO)).isNull();
}

@Test
void runTwoStepsTasklet() {
val job = provider.twoStepTaskletJobEmptyParams();
job.exec();

assertThat(job.getStats().getResult()).hasValue(DONE);
assertThat(job.getStats().getTaskletsDone()).hasValue(2);
assertThat(instanceDao.getJobNames()).containsExactly(TWO_STEPS_TASKLET);
assertThat(executionDao.findJobExecutions(job.getInstance())).hasSize(1);
assertThat(stepExecutionDao.getLastStepExecution(job.getInstance(), STEP_ONE)).isNotNull();
assertThat(stepExecutionDao.getLastStepExecution(job.getInstance(), STEP_TWO)).isNotNull();
}

@Test
void runOneStepReaderWriter() {
val job = provider.oneStepReaderWriterJobEmptyParams();
job.exec();

assertThat(job.getStats().getResult()).hasValue(DONE);
assertThat(job.getStats().getTaskletsDone()).hasValue(0);
assertThat(job.getStats().getReads()).hasValue(READS_ONE);
assertThat(job.getStats().getProcesses()).hasValue(READS_ONE);
assertThat(job.getStats().getWrites()).hasValue(READS_ONE / CHUNK_ONE);
assertThat(instanceDao.getJobNames()).containsExactly(READER_WRITER);
assertThat(executionDao.findJobExecutions(job.getInstance())).hasSize(1);
assertThat(stepExecutionDao.getLastStepExecution(job.getInstance(), STEP_ONE)).isNotNull();
assertThat(stepExecutionDao.getLastStepExecution(job.getInstance(), STEP_TWO)).isNull();
}

@Test
void runTwoStepsReaderWriter() {
val job = provider.twoStepReaderWriterJobEmptyParams();
job.exec();

assertThat(job.getStats().getResult()).hasValue(DONE);
assertThat(job.getStats().getTaskletsDone()).hasValue(0);
assertThat(job.getStats().getReads()).hasValue(READS_ONE + READS_TWO);
assertThat(job.getStats().getProcesses()).hasValue(READS_ONE + READS_TWO);
assertThat(job.getStats().getWrites()).hasValue(READS_ONE / CHUNK_ONE + READS_TWO / CHUNK_TWO);
assertThat(instanceDao.getJobNames()).containsExactly(READER_WRITER);
assertThat(executionDao.findJobExecutions(job.getInstance())).hasSize(1);
assertThat(stepExecutionDao.getLastStepExecution(job.getInstance(), STEP_ONE)).isNotNull();
assertThat(stepExecutionDao.getLastStepExecution(job.getInstance(), STEP_TWO)).isNotNull();
}
}
Loading

0 comments on commit b0f424a

Please sign in to comment.