add flag to make CSV upload wait until entries are flushed

To make it easier/possible to write stable unit test the CSV upload
can optionally wait until all entries have been flushed to disk.
This is necessary for tests that ingest data and then read the data.
This commit is contained in:
2019-12-13 18:05:20 +01:00
parent 07ad62ddd9
commit 550d7ba44e
8 changed files with 79 additions and 16 deletions

View File

@@ -9,9 +9,12 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.lucares.pdb.api.Entries;
import org.lucares.performance.db.PerformanceDb;
@@ -41,8 +44,9 @@ public class CsvUploadHandler implements PropertyKeys, DisposableBean {
this.performanceDb = performanceDb;
}
public void ingest(final List<MultipartFile> files, final CsvReaderSettings settings)
throws IllegalStateException, IOException {
public void ingest(final List<MultipartFile> files, final CsvReaderSettings settings,
final boolean waitUntilFinished)
throws IllegalStateException, IOException, InterruptedException, ExecutionException, TimeoutException {
final List<Path> tmpFiles = new ArrayList<Path>();
@@ -58,7 +62,7 @@ public class CsvUploadHandler implements PropertyKeys, DisposableBean {
throw e;
}
threadPool.submit(() -> {
final Future<?> future = threadPool.submit(() -> {
final ArrayBlockingQueue<Entries> queue = performanceDb.getQueue();
for (final Path tmpFile : tmpFiles) {
try {
@@ -74,8 +78,10 @@ public class CsvUploadHandler implements PropertyKeys, DisposableBean {
LOGGER.error("csv ingestion failed", e);
}
}
queue.add(Entries.POISON);
});
if (waitUntilFinished) {
future.get(1, TimeUnit.HOURS);
}
}
@Override