Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

Commit b4d9cf8

Browse files
author
Scott Stafford
committed
Add default values for chunk_size and thread_count
1 parent 56be89f commit b4d9cf8

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

core/src/main/java/com/marklogic/spring/batch/core/launch/support/CommandLineJobRunner.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ int start(String jobPath, String jobIdentifier, Properties parameters, OptionSet
305305
String jobName = jobIdentifier;
306306

307307
JobParameters jobParameters = jobParametersConverter.getJobParameters(parameters);
308+
308309
Assert.isTrue(parameters == null || parameters.size() == 0 || !jobParameters.isEmpty(),
309310
"Invalid JobParameters " + Arrays.asList(parameters)
310311
+ ". If parameters are provided they should be in the form name=value (no whitespace).");
@@ -548,6 +549,8 @@ protected void execute(String[] args) throws IOException {
548549
String jobIdentifier = options.valueOf(JOB_ID).toString();
549550

550551
Properties props = new Properties();
552+
props.setProperty(CHUNK_SIZE, options.valueOf(CHUNK_SIZE).toString());
553+
props.setProperty(THREAD_COUNT, options.valueOf(THREAD_COUNT).toString());
551554
List<?> nonOptionArgs = options.nonOptionArguments();
552555
int size = nonOptionArgs.size();
553556
for (int i = 0; i < size; i++) {
@@ -579,6 +582,7 @@ protected void execute(String[] args) throws IOException {
579582
protected String NEXT = "next";
580583
protected String JOB_ID = "job_id";
581584
protected String CHUNK_SIZE = "chunk_size";
585+
protected String THREAD_COUNT = "thread_count";
582586

583587
protected OptionParser buildOptionParser() {
584588
OptionParser parser = new OptionParser();
@@ -589,7 +593,8 @@ protected OptionParser buildOptionParser() {
589593
parser.accepts(NEXT, "(optional) Start the next in a sequence according to the JobParametersIncrementer in the Job");
590594
parser.accepts(RESTART, "(optional) to restart the last failed execution");
591595
parser.accepts(STOP, " (optional) to stop a running execution");
592-
parser.accepts(CHUNK_SIZE, "The chunk size of the job").withRequiredArg().defaultsTo("10");
596+
parser.accepts(CHUNK_SIZE, "The chunk size of the job").withOptionalArg().defaultsTo("100");
597+
parser.accepts(THREAD_COUNT, "The number of threads for the job").withOptionalArg().defaultsTo("4");
593598
parser.allowsUnrecognizedOptions();
594599
return parser;
595600
}

core/src/test/java/com/marklogic/spring/batch/core/launch/support/CommandLineJobRunnerTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,30 @@ public void testWithNoParameters() throws Throwable {
119119
assertEquals(new JobParameters(), StubJobLauncher.jobParameters);
120120
}
121121

122+
@Test
123+
public void testWithChunkSize() throws Throwable {
124+
String[] args = new String[] { jobPathKey, jobPath, jobNameKey, jobName, "--chunk_size", "25" };
125+
CommandLineJobRunner.main(args);
126+
assertEquals(0, StubSystemExiter.status);
127+
assertEquals("25", StubJobLauncher.jobParameters.getString("chunk_size"));
128+
}
129+
130+
@Test
131+
public void testWithDefaultChunkSize() throws Throwable {
132+
String[] args = new String[] { jobPathKey, jobPath, jobNameKey, jobName};
133+
CommandLineJobRunner.main(args);
134+
assertEquals(0, StubSystemExiter.status);
135+
assertEquals("100", StubJobLauncher.jobParameters.getString("chunk_size"));
136+
}
137+
138+
@Test
139+
public void testWithThreadCount() throws Throwable {
140+
String[] args = new String[] { jobPathKey, jobPath, jobNameKey, jobName, "--thread_count", "5" };
141+
CommandLineJobRunner.main(args);
142+
assertEquals(0, StubSystemExiter.status);
143+
assertEquals("5", StubJobLauncher.jobParameters.getString("thread_count"));
144+
}
145+
122146
@Test
123147
public void testWithInvalidStdin() throws Throwable {
124148
System.setIn(new InputStream() {

0 commit comments

Comments
 (0)