Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#498] fix(test): Fix port conflict issue in UT #499

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import static org.mockito.Mockito.mock;

import com.datastrato.graviton.Config;
import com.datastrato.graviton.rest.RESTUtils;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.Servlet;
import org.junit.jupiter.api.AfterEach;
Expand All @@ -32,17 +34,19 @@ public void tearDown() {
}

@Test
public void testInitialize() {
public void testInitialize() throws IOException {
Config config = new Config(false) {};
config.set(JettyServerConfig.WEBSERVER_HTTP_PORT, RESTUtils.findAvailablePort(5000, 6000));
JettyServerConfig serverConfig = JettyServerConfig.fromConfig(config);
jettyServer.initialize(serverConfig, "test");

// TODO might be nice to have an isInitalised method or similar?
}

@Test
public void testStartAndStop() throws RuntimeException {
public void testStartAndStop() throws RuntimeException, IOException {
Config config = new Config(false) {};
config.set(JettyServerConfig.WEBSERVER_HTTP_PORT, RESTUtils.findAvailablePort(5000, 6000));
JettyServerConfig serverConfig = JettyServerConfig.fromConfig(config);
jettyServer.initialize(serverConfig, "test");
jettyServer.start();
Expand All @@ -51,8 +55,9 @@ public void testStartAndStop() throws RuntimeException {
}

@Test
public void testAddServletAndFilter() throws RuntimeException {
public void testAddServletAndFilter() throws RuntimeException, IOException {
Config config = new Config(false) {};
config.set(JettyServerConfig.WEBSERVER_HTTP_PORT, RESTUtils.findAvailablePort(5000, 6000));
JettyServerConfig serverConfig = JettyServerConfig.fromConfig(config);
jettyServer.initialize(serverConfig, "test");
jettyServer.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.datastrato.graviton.aux.AuxiliaryServiceManager;
import com.datastrato.graviton.rest.RESTUtils;
import com.datastrato.graviton.server.web.JettyServerConfig;
import com.google.common.collect.ImmutableMap;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.AfterEach;
Expand All @@ -30,17 +32,17 @@ public class TestGravitonServer {
private ServerConfig spyServerConfig;

@BeforeAll
void initConfig() {
String confPath =
System.getenv("GRAVITON_HOME")
+ File.separator
+ "conf"
+ File.separator
+ "graviton.conf.template";
ServerConfig serverConfig = GravitonServer.loadConfig(confPath);
void initConfig() throws IOException {
ServerConfig serverConfig = new ServerConfig();
serverConfig.loadFromMap(
ImmutableMap.of(
ENTRY_KV_ROCKSDB_BACKEND_PATH.getKey(),
ROCKS_DB_STORE_PATH,
GravitonServer.WEBSERVER_CONF_PREFIX + JettyServerConfig.WEBSERVER_HTTP_PORT.getKey(),
String.valueOf(RESTUtils.findAvailablePort(5000, 6000))),
yuqi1129 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw the same exception in com.datastrato.graviton.server.web.TestJettyServer, is it need to do the same process?

> Task :server-common:test

TestJettyServer > testStartAndStop() FAILED
    java.lang.RuntimeException at TestJettyServer.java:48
        Caused by: java.io.IOException at TestJettyServer.java:48
            Caused by: java.net.BindException at TestJettyServer.java:48

t -> true);

spyServerConfig = Mockito.spy(serverConfig);
Mockito.when(spyServerConfig.get(ENTRY_KV_ROCKSDB_BACKEND_PATH))
.thenReturn(ROCKS_DB_STORE_PATH);

Mockito.when(
spyServerConfig.getConfigsWithPrefix(
Expand Down
Loading