This commit is contained in:
Zoltan Haindrich 2024-06-17 16:25:03 +00:00
parent f5720ce97d
commit 6dd62fb7c6
6 changed files with 29 additions and 41 deletions

View File

@ -330,11 +330,6 @@
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-core</artifactId>
</dependency>
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-kqueue</artifactId>

View File

@ -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();
}

View File

@ -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()

View File

@ -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<String>
{
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);
}

View File

@ -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());
}
}

View File

@ -0,0 +1,4 @@
#started
!connect druidtest:///
select * from numfoo;
!ok