launcher-x

This commit is contained in:
Zoltan Haindrich 2024-05-28 15:44:22 +00:00
parent 07e05a664d
commit 295c09a03c
2 changed files with 95 additions and 60 deletions

View File

@ -26,30 +26,33 @@ import org.apache.druid.sql.calcite.SqlTestFrameworkConfig;
import org.apache.druid.sql.calcite.SqlTestFrameworkConfig.ConfigurationInstance;
import org.apache.druid.sql.calcite.SqlTestFrameworkConfig.SqlTestFrameworkConfigStore;
import org.apache.druid.sql.calcite.util.SqlTestFramework;
import org.junit.Test;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;
import java.sql.SQLException;
import static org.junit.Assert.assertNotEquals;
public class Launcher
{
static final SqlTestFrameworkConfigStore CONFIG_STORE = new SqlTestFrameworkConfigStore();
private static Logger log = new Logger(Launcher.class);
private final SqlTestFramework framework;
private final ConfigurationInstance configurationInstance;
private Lifecycle lifecycle;
@Test
public void runIt() throws Exception
public Launcher() throws Exception
{
Launcher.main3(null);
configurationInstance = getConfigurationInstance();
framework = configurationInstance.framework;
}
private static ConfigurationInstance getCI2() throws SQLException, Exception
public void start()
{
lifecycle = GuiceRunnable.initLifecycle(framework.injector(), log);
}
public void shutdown()
{
lifecycle.stop();
}
private static ConfigurationInstance getConfigurationInstance() throws SQLException, Exception
{
SqlTestFrameworkConfig config = SqlTestFrameworkConfig.fromURL("druidtest:///");
@ -59,50 +62,4 @@ public class Launcher
);
return ci;
}
private static void main3(Object object) throws Exception
{
SqlTestFramework framework = getCI2().framework;
Lifecycle lifecycle = GuiceRunnable.initLifecycle(framework.injector(), log);
chk1();
chkStatus();
System.out.println("-------------------booted up-------------------");
lifecycle.join();
}
private static void chk1() throws IOException, InterruptedException
{
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://localhost:12345/druid/v2/sql"))
.header("Content-Type", "application/json")
.POST(BodyPublishers.ofString("{\"query\":\"Select * from foo\"}"))
.build();
System.out.println(request);
HttpClient hc = HttpClient.newHttpClient();
HttpResponse<String> a = hc.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(a);
assertNotEquals(400, a.statusCode());
}
private static void chkStatus() throws IOException, InterruptedException
{
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://localhost:12345/status"))
.header("Content-Type", "application/json")
.GET()
.build();
System.out.println(request);
// request.
HttpClient hc = HttpClient.newHttpClient();
HttpResponse<String> a = hc.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(a);
assertNotEquals(400, a.statusCode());
}
}

View File

@ -0,0 +1,78 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.druid.quidem;
import org.apache.druid.sql.calcite.SqlTestFrameworkConfig.SqlTestFrameworkConfigStore;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;
import static org.testng.Assert.assertEquals;
public class LauncherSmokeTest
{
static final SqlTestFrameworkConfigStore CONFIG_STORE = new SqlTestFrameworkConfigStore();
private static Launcher launcher;
@BeforeClass
public static void setUp() throws Exception
{
launcher = new Launcher();
launcher.start();
}
@AfterClass
public static void tearDown()
{
launcher.shutdown();
}
@Test
public void chkSelectFromFoo() throws IOException, InterruptedException
{
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://localhost:12345/druid/v2/sql"))
.header("Content-Type", "application/json")
.POST(BodyPublishers.ofString("{\"query\":\"Select * from foo\"}"))
.build();
HttpClient hc = HttpClient.newHttpClient();
HttpResponse<String> a = hc.send(request, HttpResponse.BodyHandlers.ofString());
assertEquals(200, a.statusCode());
}
@Test
public void chkStatusWorks() throws IOException, InterruptedException
{
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://localhost:12345/status"))
.header("Content-Type", "application/json")
.GET()
.build();
HttpClient hc = HttpClient.newHttpClient();
HttpResponse<String> a = hc.send(request, HttpResponse.BodyHandlers.ofString());
assertEquals(200, a.statusCode());
}
}