Skip to content

Commit

Permalink
test: Disabled progress bar logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Ruaux committed Oct 19, 2022
1 parent 470f108 commit b580638
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FileTests {
@Test
void importJSON() throws UnexpectedInputException, ParseException, NonTransientResourceException, Exception {
FileImportCommand command = FileImportCommand.builder().build();
Iterator<Map<String, Object>> iterator = command.read(FileIntegrationTests.BEERS_JSON_URL);
Iterator<Map<String, Object>> iterator = command.read(RiotFileIntegrationTests.BEERS_JSON_URL);
Assertions.assertTrue(iterator.hasNext());
Map<String, Object> beer1 = iterator.next();
Assertions.assertEquals(13, beer1.size());
Expand All @@ -28,7 +28,7 @@ void importJSON() throws UnexpectedInputException, ParseException, NonTransientR
iterator.next();
count++;
}
Assertions.assertEquals(FileIntegrationTests.BEER_JSON_COUNT, count);
Assertions.assertEquals(RiotFileIntegrationTests.BEER_JSON_COUNT, count);
}

@Test
Expand All @@ -44,7 +44,7 @@ void importCSV() throws UnexpectedInputException, ParseException, NonTransientRe
iterator.next();
count++;
}
Assertions.assertEquals(FileIntegrationTests.BEER_CSV_COUNT, count);
Assertions.assertEquals(RiotFileIntegrationTests.BEER_CSV_COUNT, count);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.redis.lettucemod.api.sync.RedisModulesCommands;
import com.redis.riot.AbstractRiotIntegrationTests;
import com.redis.riot.ProgressStyle;
import com.redis.riot.file.resource.XmlItemReader;
import com.redis.riot.file.resource.XmlItemReaderBuilder;
import com.redis.riot.file.resource.XmlObjectReader;
Expand All @@ -48,7 +49,7 @@
import picocli.CommandLine;

@SuppressWarnings("unchecked")
class FileIntegrationTests extends AbstractRiotIntegrationTests {
class RiotFileIntegrationTests extends AbstractRiotIntegrationTests {

public static final String BEERS_JSON_URL = "https://storage.googleapis.com/jrx/beers.json";
public static final int BEER_CSV_COUNT = 2410;
Expand All @@ -58,7 +59,7 @@ class FileIntegrationTests extends AbstractRiotIntegrationTests {

@BeforeAll
public void setupAll() throws IOException {
tempDir = Files.createTempDirectory(FileIntegrationTests.class.getName());
tempDir = Files.createTempDirectory(RiotFileIntegrationTests.class.getName());
}

private String replace(String file) {
Expand Down Expand Up @@ -449,6 +450,7 @@ void exportXml(RedisTestContext redis) throws Exception {
void importJsonAPI(RedisTestContext redis) throws Exception {
// riot-file import hset --keyspace beer --keys id
FileImportCommand command = new FileImportCommand();
command.getTransferOptions().setProgressStyle(ProgressStyle.NONE);
command.getOptions().setFiles(Collections.singletonList(BEERS_JSON_URL));
HsetCommand hset = new HsetCommand();
hset.getKeyOptions().setKeyspace("beer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import io.lettuce.core.api.sync.RedisStreamCommands;

@SuppressWarnings("unchecked")
class GenIntegrationTests extends AbstractRiotIntegrationTests {
class RiotGenIntegrationTests extends AbstractRiotIntegrationTests {

private final RedisModulesContainer redisMod = new RedisModulesContainer(
RedisModulesContainer.DEFAULT_IMAGE_NAME.withTag(RedisModulesContainer.DEFAULT_TAG));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.redis.riot.AbstractTransferCommand;
import com.redis.riot.JobCommandContext;
import com.redis.riot.ProgressMonitor;
import com.redis.riot.ProgressMonitor.Style;
import com.redis.riot.ProgressStyle;
import com.redis.riot.RedisOptions;
import com.redis.riot.RedisReaderOptions;
import com.redis.spring.batch.RedisItemReader;
Expand Down Expand Up @@ -119,7 +119,7 @@ public ExitStatus afterStep(StepExecution stepExecution) {
return ExitStatus.COMPLETED;
}
try {
Thread.sleep(progressOptions.getUpdateIntervalMillis());
Thread.sleep(getTransferOptions().getProgressUpdateInterval());
} catch (InterruptedException e) {
log.fine("Verification interrupted");
Thread.currentThread().interrupt();
Expand Down Expand Up @@ -156,7 +156,8 @@ private String extraMessage(Results results) {
}

private String extraMessageFormat() {
if (progressOptions.getStyle() == Style.BAR || progressOptions.getStyle() == Style.BLOCK) {
ProgressStyle progressStyle = getTransferOptions().getProgressStyle();
if (progressStyle == ProgressStyle.BAR || progressStyle == ProgressStyle.BLOCK) {
return COMPARE_MESSAGE_COLOR;
}
return COMPARE_MESSAGE_ASCII;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

@Testcontainers
@SuppressWarnings("unchecked")
class RedisIntegrationTests extends AbstractRiotIntegrationTests {
class RiotRedisIntegrationTests extends AbstractRiotIntegrationTests {

private final Logger log = LoggerFactory.getLogger(getClass());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ public abstract class AbstractTransferCommand extends AbstractJobCommand {

@Mixin
private TransferOptions options = new TransferOptions();
@Mixin
protected ProgressMonitorOptions progressOptions = new ProgressMonitorOptions();

public void setTransferOptions(TransferOptions transferOptions) {
this.options = transferOptions;
public TransferOptions getTransferOptions() {
return options;
}

public void setProgressOptions(ProgressMonitorOptions progressOptions) {
this.progressOptions = progressOptions;
public void setTransferOptions(TransferOptions options) {
this.options = options;
}

protected <I, O> SimpleStepBuilder<I, O> step(JobCommandContext context, String name, ItemReader<I> reader,
Expand All @@ -61,7 +59,7 @@ protected <I, O> Job job(JobCommandContext context, String name, SimpleStepBuild
}

protected ProgressMonitor.Builder progressMonitor() {
return progressOptions.monitor();
return options.progressMonitor();
}

protected <I, O> FaultTolerantStepBuilder<I, O> step(SimpleStepBuilder<I, O> step, ProgressMonitor monitor) {
Expand All @@ -77,7 +75,7 @@ protected <I, O> FaultTolerantStepBuilder<I, O> step(SimpleStepBuilder<I, O> ste
} else {
step.taskExecutor(new SyncTaskExecutor());
}
if (progressOptions.isEnabled()) {
if (options.isProgressEnabled()) {
step.listener((StepExecutionListener) monitor);
step.listener((ItemWriteListener<Object>) monitor);
}
Expand Down
12 changes: 4 additions & 8 deletions core/riot-core/src/main/java/com/redis/riot/ProgressMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@

public class ProgressMonitor implements StepExecutionListener, ItemWriteListener<Object> {

public enum Style {
BLOCK, BAR, UNICODE, ASCII, NONE
}

private final Style style;
private final ProgressStyle style;
private final String task;
private final Duration updateInterval;
private final Optional<Supplier<Long>> initialMax;
Expand Down Expand Up @@ -105,19 +101,19 @@ public void afterWrite(List<? extends Object> items) {
}
}

public static Builder style(Style style) {
public static Builder style(ProgressStyle style) {
return new Builder(style);
}

public static class Builder {

private final Style style;
private final ProgressStyle style;
private String task;
private Duration updateInterval = Duration.ofMillis(300);
private Optional<Supplier<Long>> initialMax = Optional.empty();
private Optional<Supplier<String>> extraMessage = Optional.empty();

public Builder(Style style) {
public Builder(ProgressStyle style) {
this.style = style;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.redis.riot;

public enum ProgressStyle {
BLOCK, BAR, UNICODE, ASCII, NONE
}
34 changes: 34 additions & 0 deletions core/riot-core/src/main/java/com/redis/riot/TransferOptions.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.redis.riot;

import java.time.Duration;

import com.redis.riot.ProgressMonitor.Builder;

import picocli.CommandLine.Option;

public class TransferOptions {
Expand All @@ -20,6 +24,36 @@ public class TransferOptions {
@Option(names = "--skip-limit", description = "LIMIT skip policy: max number of failed items before considering the transfer has failed (default: ${DEFAULT-VALUE}).", paramLabel = "<int>")
private int skipLimit = 3;

@Option(names = "--progress", description = "Style of progress bar: ${COMPLETION-CANDIDATES} (default: ${DEFAULT-VALUE}),", paramLabel = "<style>")
private ProgressStyle progressStyle = ProgressStyle.BAR;

@Option(names = "--progress-interval", description = "Progress update interval in milliseconds (default: ${DEFAULT-VALUE}).", paramLabel = "<ms>", hidden = true)
private long progressUpdateInterval = 30;

public ProgressStyle getProgressStyle() {
return progressStyle;
}

public long getProgressUpdateInterval() {
return progressUpdateInterval;
}

public void setProgressStyle(ProgressStyle style) {
this.progressStyle = style;
}

public void setProgressUpdateInterval(long millis) {
this.progressUpdateInterval = millis;
}

public Builder progressMonitor() {
return ProgressMonitor.style(progressStyle).updateInterval(Duration.ofMillis(progressUpdateInterval));
}

public boolean isProgressEnabled() {
return getProgressStyle() != ProgressStyle.NONE;
}

public long getSleep() {
return sleep;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.UUID;

import org.junit.jupiter.api.BeforeAll;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionException;
import org.springframework.batch.core.step.builder.SimpleStepBuilder;
Expand Down Expand Up @@ -59,8 +58,7 @@ protected void generate(ItemReader<DataStructure<String>> reader, RedisTestConte

protected <T> JobExecution run(String name, int chunkSize, ItemReader<T> reader, ItemWriter<T> writer)
throws JobExecutionException {
Job job = jobRunner.job(name).start(step(name, chunkSize, reader, writer).build()).build();
return jobRunner.run(job);
return jobRunner.run(jobRunner.job(name).start(step(name, chunkSize, reader, writer).build()).build());
}

protected void generate(int chunkSize, ItemReader<DataStructure<String>> reader, RedisTestContext redis)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ protected int execute(String filename, RedisTestContext redis, Consumer<CommandL
RiotApp app = app();
RiotCommandLine commandLine = app.commandLine();
CommandLine.ParseResult parseResult = commandLine.parseArgs(args(filename));
Object command = parseResult.subcommand().commandSpec().commandLine().getCommand();
if (command instanceof OperationCommand) {
command = parseResult.subcommand().commandSpec().parent().commandLine().getCommand();
}
if (command instanceof AbstractTransferCommand) {
AbstractTransferCommand transferCommand = (AbstractTransferCommand) command;
transferCommand.getTransferOptions().setProgressStyle(ProgressStyle.NONE);
}
configure(app, redis);
for (Consumer<CommandLine.ParseResult> configurator : configurators) {
configurator.accept(parseResult);
Expand Down

0 comments on commit b580638

Please sign in to comment.