Skip to content

Commit

Permalink
fix checkstyle;
Browse files Browse the repository at this point in the history
  • Loading branch information
auden-woolfson committed Feb 4, 2025
1 parent 590fffb commit 84c49f5
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -495,4 +495,4 @@ public DispatcherType getDispatcherType()
{
throw new UnsupportedOperationException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.testng.annotations.Test;

import javax.servlet.http.HttpServletRequest;

import java.io.File;
import java.io.FileOutputStream;
import java.net.URI;
Expand All @@ -46,79 +47,79 @@
import static org.testng.Assert.assertFalse;

public class TestHealthChecks
{
private List<TestingPrestoServer> prestoServers;
private ClusterManager clusterManager;
{
private List<TestingPrestoServer> prestoServers;
private ClusterManager clusterManager;

@BeforeClass
public void setup()
@BeforeClass
public void setup()
throws Exception
{
String configTemplate = new String(
Files.readAllBytes(Paths.get(this.getClass().getClassLoader().getResource("health-check-test-router-template.json").getPath())));
{
String configTemplate = new String(
Files.readAllBytes(Paths.get(this.getClass().getClassLoader().getResource("health-check-test-router-template.json").getPath())));

File configFile = File.createTempFile("router", "json");
File configFile = File.createTempFile("router", "json");

Logging.initialize();
Logging.initialize();

// set up server
ImmutableList.Builder<TestingPrestoServer> builder = ImmutableList.builder();
for (int i = 0; i < 3; ++i) {
TestingPrestoServer server = new TestingPrestoServer();
server.installPlugin(new TpchPlugin());
server.createCatalog("tpch", "tpch");
server.refreshNodes();
builder.add(server);
}
// set up server
ImmutableList.Builder<TestingPrestoServer> builder = ImmutableList.builder();
for (int i = 0; i < 3; ++i) {
TestingPrestoServer server = new TestingPrestoServer();
server.installPlugin(new TpchPlugin());
server.createCatalog("tpch", "tpch");
server.refreshNodes();
builder.add(server);
}

prestoServers = builder.build();
prestoServers = builder.build();

for (TestingPrestoServer s : prestoServers) {
configTemplate = configTemplate.replaceFirst("\\$\\{SERVERS}", String.format("[ \"%s\" ]", s.getBaseUrl().toString()));
}
for (TestingPrestoServer s : prestoServers) {
configTemplate = configTemplate.replaceFirst("\\$\\{SERVERS}", String.format("[ \"%s\" ]", s.getBaseUrl().toString()));
}

FileOutputStream fileOutputStream = new FileOutputStream(configFile);
fileOutputStream.write(configTemplate.getBytes(UTF_8));
FileOutputStream fileOutputStream = new FileOutputStream(configFile);
fileOutputStream.write(configTemplate.getBytes(UTF_8));

fileOutputStream.close();
fileOutputStream.close();

Bootstrap app = new Bootstrap(
new TestingNodeModule("test"),
new TestingHttpServerModule(), new JsonModule(),
new JaxrsModule(true),
new ServerSecurityModule(),
new RouterModule());
Bootstrap app = new Bootstrap(
new TestingNodeModule("test"),
new TestingHttpServerModule(), new JsonModule(),
new JaxrsModule(true),
new ServerSecurityModule(),
new RouterModule());

Injector injector = app.doNotInitializeLogging().setRequiredConfigurationProperty("router.config-file", configFile.getAbsolutePath()).initialize();
clusterManager = injector.getInstance(ClusterManager.class);
}
Injector injector = app.doNotInitializeLogging().setRequiredConfigurationProperty("router.config-file", configFile.getAbsolutePath()).initialize();
clusterManager = injector.getInstance(ClusterManager.class);
}

@AfterClass(alwaysRun = true)
public void tearDownServer()
throws Exception
{
for (TestingPrestoServer prestoServer : prestoServers) {
prestoServer.close();
}
@AfterClass(alwaysRun = true)
public void tearDownServer()
throws Exception
{
for (TestingPrestoServer prestoServer : prestoServers) {
prestoServer.close();
}
}

@Test(enabled = false)
public void testHealthChecks()
{
prestoServers.get(0).stopResponding();
List<URI> destinations = new ArrayList();
for (int i = 0; i < 3; i++) {
destinations.add(getDestinationWrapper().orElse(URI.create("null")));
}
assertFalse(destinations.contains(prestoServers.get(0).getBaseUrl()));
@Test(enabled = false)
public void testHealthChecks()
{
prestoServers.get(0).stopResponding();
List<URI> destinations = new ArrayList();
for (int i = 0; i < 3; i++) {
destinations.add(getDestinationWrapper().orElse(URI.create("null")));
}
assertFalse(destinations.contains(prestoServers.get(0).getBaseUrl()));
}

private Optional<URI> getDestinationWrapper()
{
HttpServletRequest request = new MockRouterHttpServletRequest(
ImmutableListMultimap.of(),
"testRemote",
ImmutableMap.of());
return clusterManager.getDestination(new RequestInfo(request, ""));
}
private Optional<URI> getDestinationWrapper()
{
HttpServletRequest request = new MockRouterHttpServletRequest(
ImmutableListMultimap.of(),
"testRemote",
ImmutableMap.of());
return clusterManager.getDestination(new RequestInfo(request, ""));
}
}

0 comments on commit 84c49f5

Please sign in to comment.