From 6dd62fb7c6bb122fbdbf0537f50cf1a9a8b847ee Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Mon, 17 Jun 2024 16:25:03 +0000 Subject: [PATCH] updates --- quidem-it/pom.xml | 5 --- .../org/apache/druid/quidem/Launcher.java | 1 - .../druid/quidem/QuidemCaptureResource.java | 33 +++++-------------- .../apache/druid/quidem/QuidemRecorder.java | 13 +++++--- .../java/org/apache/druid/quidem/QTest.java | 14 ++++---- .../record-1718641409720.txt | 4 +++ 6 files changed, 29 insertions(+), 41 deletions(-) create mode 100644 quidem-it/src/test/quidem/org.apache.druid.quidem.QTest/record-1718641409720.txt diff --git a/quidem-it/pom.xml b/quidem-it/pom.xml index cb6192cc3f9..6cd43fbb0e7 100644 --- a/quidem-it/pom.xml +++ b/quidem-it/pom.xml @@ -330,11 +330,6 @@ com.github.docker-java docker-java-core - - com.github.javafaker - javafaker - 1.0.2 - io.netty netty-transport-native-kqueue diff --git a/quidem-it/src/main/java/org/apache/druid/quidem/Launcher.java b/quidem-it/src/main/java/org/apache/druid/quidem/Launcher.java index 47dc1fe8e52..13ac09232ae 100644 --- a/quidem-it/src/main/java/org/apache/druid/quidem/Launcher.java +++ b/quidem-it/src/main/java/org/apache/druid/quidem/Launcher.java @@ -70,7 +70,6 @@ public class Launcher } log.info("Starting Quidem with URI[%s]", quidemUri); Launcher launcher = new Launcher(quidemUri); - System.exit(1); launcher.start(); launcher.lifecycle.join(); } diff --git a/quidem-it/src/main/java/org/apache/druid/quidem/QuidemCaptureResource.java b/quidem-it/src/main/java/org/apache/druid/quidem/QuidemCaptureResource.java index cd1001132b6..174dac22664 100644 --- a/quidem-it/src/main/java/org/apache/druid/quidem/QuidemCaptureResource.java +++ b/quidem-it/src/main/java/org/apache/druid/quidem/QuidemCaptureResource.java @@ -19,10 +19,8 @@ package org.apache.druid.quidem; -import com.github.javafaker.Faker; -import com.github.javafaker.Pokemon; import com.google.inject.Inject; -import org.apache.hadoop.util.StringUtils; +import org.apache.druid.java.util.common.StringUtils; import javax.inject.Named; import javax.ws.rs.GET; @@ -31,13 +29,13 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; import java.net.URI; @Path("/quidem") public class QuidemCaptureResource { + public static final File RECORD_PATH = ProjectPathUtils + .getPathFromProjectRoot("quidem-it/src/test/quidem/org.apache.druid.quidem.QTest"); private URI quidemURI; private QuidemRecorder recorder = null; @@ -46,12 +44,7 @@ public class QuidemCaptureResource { this.quidemURI = quidemURI; if (withAutoStart()) { - try { - start(); - } - catch (IOException e) { - throw new RuntimeException(e); - } + start(); } } @@ -63,28 +56,20 @@ public class QuidemCaptureResource @GET @Path("/start") @Produces(MediaType.TEXT_PLAIN) - public synchronized String start() throws IOException + public synchronized String start() { stopIfRunning(); recorder = new QuidemRecorder( quidemURI, - new FileOutputStream(extracted()) + genRecordFilePath() ); return recorder.toString(); } - private File extracted() + private File genRecordFilePath() { - File dir = QTest.testRoot(); - Pokemon pokemon = Faker.instance().pokemon(); - String fileName = StringUtils.format("quidem-%s.txt", pokemon.name()); - return new File(dir, fileName); - } - public static void main(String[] args) - { - Pokemon pokemon = Faker.instance().pokemon(); - System.out.println(Faker.instance().aviation().aircraft()); - + String fileName = StringUtils.format("record-%d.txt", System.currentTimeMillis()); + return new File(RECORD_PATH, fileName); } private synchronized void stopIfRunning() diff --git a/quidem-it/src/main/java/org/apache/druid/quidem/QuidemRecorder.java b/quidem-it/src/main/java/org/apache/druid/quidem/QuidemRecorder.java index ec75d6cef0b..7ecf337546c 100644 --- a/quidem-it/src/main/java/org/apache/druid/quidem/QuidemRecorder.java +++ b/quidem-it/src/main/java/org/apache/druid/quidem/QuidemRecorder.java @@ -21,25 +21,28 @@ package org.apache.druid.quidem; import org.apache.druid.sql.calcite.run.DruidHook; +import java.io.File; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.PrintStream; import java.io.UnsupportedEncodingException; import java.net.URI; import java.nio.charset.StandardCharsets; +import java.util.Date; public class QuidemRecorder implements AutoCloseable, DruidHook { private PrintStream printStream; - public QuidemRecorder(URI quidemURI, FileOutputStream fileOutputStream) + public QuidemRecorder(URI quidemURI, File file) { try { - this.printStream = new PrintStream(fileOutputStream, true, StandardCharsets.UTF_8.name()); + this.printStream = new PrintStream(new FileOutputStream(file), true, StandardCharsets.UTF_8.name()); } - catch (UnsupportedEncodingException e) { - throw new RuntimeException(); + catch (UnsupportedEncodingException | FileNotFoundException e) { + throw new RuntimeException(e); } - printStream.println("#started"); + printStream.println("#started " + new Date()); printStream.println("!connect " + quidemURI.toString()); DruidHook.register(DruidHook.SQL, this); } diff --git a/quidem-it/src/test/java/org/apache/druid/quidem/QTest.java b/quidem-it/src/test/java/org/apache/druid/quidem/QTest.java index 3d04fbe166d..006e1e8f72d 100644 --- a/quidem-it/src/test/java/org/apache/druid/quidem/QTest.java +++ b/quidem-it/src/test/java/org/apache/druid/quidem/QTest.java @@ -21,21 +21,23 @@ package org.apache.druid.quidem; import java.io.File; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class QTest extends DruidQuidemTestBase { public QTest() { super(); + + assertEquals( + QuidemCaptureResource.RECORD_PATH + , getTestRoot()); + } @Override protected File getTestRoot() { - return testRoot(); - } - - public static File testRoot() - { - return ProjectPathUtils.getPathFromProjectRoot("quidem-it/src/test/quidem/" + QTest.class.getName()); + return ProjectPathUtils.getPathFromProjectRoot("quidem-it/src/test/quidem/" + getClass().getName()); } } diff --git a/quidem-it/src/test/quidem/org.apache.druid.quidem.QTest/record-1718641409720.txt b/quidem-it/src/test/quidem/org.apache.druid.quidem.QTest/record-1718641409720.txt new file mode 100644 index 00000000000..7c4e4db66d7 --- /dev/null +++ b/quidem-it/src/test/quidem/org.apache.druid.quidem.QTest/record-1718641409720.txt @@ -0,0 +1,4 @@ +#started +!connect druidtest:/// +select * from numfoo; +!ok