Skip to content

Instantly share code, notes, and snippets.

View fmbenhassine's full-sized avatar

Mahmoud Ben Hassine fmbenhassine

View GitHub Profile
@fmbenhassine
fmbenhassine / DemoExitCodeApplication.java
Created July 21, 2018 16:29
Custom exit code with boot #SpringBatch
package com.example.demoexitcode;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoExitCodeApplication {
public static void main(String[] args) {
System.exit(
@fmbenhassine
fmbenhassine / PartitionJobSample.java
Created June 7, 2018 13:44
Spring Batch local partitioning sample #SpringBatch
/*
* Copyright 2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@fmbenhassine
fmbenhassine / MyJob.java
Last active May 17, 2020 20:54
Spring Batch example of how to use a ClassifierCompositeItemWriter #SpringBatch https://stackoverflow.com/questions/53377660
package org.springframework.batch.sample;
import java.util.Arrays;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
@fmbenhassine
fmbenhassine / DemoValidationApplication.java
Last active October 17, 2021 12:42
Spring Batch Bean Validation example #SpringBatch
package com.example.demovalidation;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoValidationApplication {
public static void main(String[] args) {
SpringApplication.run(DemoValidationApplication.class, args);
@fmbenhassine
fmbenhassine / RemoteChunkingJobFunctionalTests.java
Last active May 24, 2018 20:37
Spring Batch "remote" chunking sample with embedded JMS broker #SpringBatch
/*
* Copyright 2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@fmbenhassine
fmbenhassine / FileIngestionJobConfiguration.java
Last active July 18, 2018 20:06
Spring Batch File ingestion job sample #SpringBatch
package io.github.benas.sbi;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import javax.sql.DataSource;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
@fmbenhassine
fmbenhassine / RepeatTest.java
Created April 3, 2018 09:35
JUnit rule to repeat a test. Useful when testing multi-threaded behaviour which might succeed in one attempt but fail in another one.
public class RepeatTest implements TestRule {
private int count;
public RepeatTest(int count) {
if (count < 2 ) {
throw new IllegalArgumentException("Count must be >= 2");
}
this.count = count;
}
@fmbenhassine
fmbenhassine / ContextAwareWork.java
Last active May 24, 2018 20:39
Example of how to create an Easy Flows workflow with execution data passed between steps #EasyFlows
package org.jeasy.flows.work;
public abstract class ContextAwareWork implements Work {
private String name;
protected ExecutionContext executionContext;
public ContextAwareWork(String name, ExecutionContext executionContext) {
this.name = name;
this.executionContext = executionContext;
@fmbenhassine
fmbenhassine / DateFormatTests.java
Created January 11, 2018 21:03
Going back and forth between Date and String is not guaranteed to work..
package org.springframework.batch.item;
import org.junit.Test;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import static org.junit.Assert.assertEquals;
@fmbenhassine
fmbenhassine / GreetingTasklet.java
Last active May 24, 2018 20:41
Vanilla Spring Batch hello world job using an in-memory database, configured with XML and packaged in a standalone jar #SpringBatch
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
public class GreetingTasklet implements Tasklet {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
Object name = chunkContext.getStepContext().getJobParameters().get("name");