Skip to content

Commit

Permalink
Fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
dilanSachi committed Jan 9, 2024
1 parent 0f72561 commit 40ded00
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.netty.util.CharsetUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -62,6 +63,7 @@ public class Http2TcpServerGoAwayMultipleStreamScenarioTest {

private static final Logger LOGGER = LoggerFactory.getLogger(Http2TcpServerGoAwayMultipleStreamScenarioTest.class);
private HttpClientConnector h2ClientWithPriorKnowledge;
private ServerSocket serverSocket;

@BeforeClass
public void setup() throws InterruptedException {
Expand Down Expand Up @@ -116,7 +118,6 @@ private void testGoAwayWhenReceivingHeadersInAMultipleStreamScenario() {

private void runTcpServer(int port) {
new Thread(() -> {
ServerSocket serverSocket;
try {
serverSocket = new ServerSocket(port);
LOGGER.info("HTTP/2 TCP Server listening on port " + port);
Expand All @@ -126,8 +127,6 @@ private void runTcpServer(int port) {
sendGoAwayForASingleStreamInAMultipleStreamScenario(outputStream);
} catch (Exception e) {
LOGGER.error(e.getMessage());
} finally {
serverSocket.close();
}
} catch (IOException e) {
LOGGER.error(e.getMessage());
Expand Down Expand Up @@ -158,4 +157,10 @@ private static void sendGoAwayForASingleStreamInAMultipleStreamScenario(OutputSt
outputStream.write(DATA_FRAME_STREAM_03);
Thread.sleep(END_SLEEP_TIME);
}

@AfterClass
public void cleanUp() throws IOException {
h2ClientWithPriorKnowledge.close();
serverSocket.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.netty.util.CharsetUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -58,19 +59,16 @@ public class Http2TcpServerGoAwaySingleStreamScenarioTest {

private static final Logger LOGGER = LoggerFactory.getLogger(Http2TcpServerGoAwaySingleStreamScenarioTest.class);
private HttpClientConnector h2ClientWithPriorKnowledge;
private ServerSocket serverSocket;

@BeforeMethod
public void setup(Method method) throws InterruptedException {
if (method.getName().equals("testGoAwayWhenReceivingHeadersForASingleStream")) {
runTcpServer(TestUtil.HTTP_SERVER_PORT, 1);
} else {
runTcpServer(TestUtil.HTTP_SERVER_PORT, 2);
}
h2ClientWithPriorKnowledge = TestUtils.setupHttp2PriorKnowledgeClient();
}

@Test (description = "In this, server sends headers and data for the accepted stream")
private void testGoAwayWhenReceivingHeadersForASingleStream() {
runTcpServer(TestUtil.HTTP_SERVER_PORT, 1);
HttpCarbonMessage httpCarbonMessage = MessageGenerator.generateRequest(HttpMethod.POST, "Test Http2 Message");
try {
CountDownLatch latch = new CountDownLatch(1);
Expand All @@ -88,6 +86,7 @@ private void testGoAwayWhenReceivingHeadersForASingleStream() {

@Test (description = "In this, server exits without sending the headers and data for the accepted stream as well")
private void testGoAwayAndServerExitWhenReceivingHeadersForASingleStream() {
runTcpServer(TestUtil.HTTP_SERVER_PORT, 2);
HttpCarbonMessage httpCarbonMessage = MessageGenerator.generateRequest(HttpMethod.POST, "Test Http2 Message");
try {
CountDownLatch latch = new CountDownLatch(1);
Expand All @@ -110,7 +109,6 @@ private void testGoAwayAndServerExitWhenReceivingHeadersForASingleStream() {

private void runTcpServer(int port, int option) {
new Thread(() -> {
ServerSocket serverSocket;
try {
serverSocket = new ServerSocket(port);
LOGGER.info("HTTP/2 TCP Server listening on port " + port);
Expand All @@ -124,8 +122,6 @@ private void runTcpServer(int port, int option) {
}
} catch (Exception e) {
LOGGER.error(e.getMessage());
} finally {
serverSocket.close();
}
} catch (IOException e) {
LOGGER.error(e.getMessage());
Expand Down Expand Up @@ -158,4 +154,10 @@ private static void sendGoAwayForASingleStream(OutputStream outputStream) throws
outputStream.write(DATA_FRAME_STREAM_03);
Thread.sleep(END_SLEEP_TIME);
}

@AfterMethod
public void cleanUp() throws IOException {
h2ClientWithPriorKnowledge.close();
serverSocket.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.netty.handler.codec.http.HttpMethod;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -56,6 +57,7 @@ public class Http2TcpServerGoAwayWhileReceivingBodyScenarioTest {
private static final Logger LOGGER =
LoggerFactory.getLogger(Http2TcpServerGoAwayWhileReceivingBodyScenarioTest.class);
private HttpClientConnector h2ClientWithPriorKnowledge;
private ServerSocket serverSocket;

@BeforeClass
public void setup() throws InterruptedException {
Expand Down Expand Up @@ -87,7 +89,6 @@ private void testGoAwayWhenReceivingBodyForASingleStream() {

private void runTcpServer(int port) {
new Thread(() -> {
ServerSocket serverSocket;
try {
serverSocket = new ServerSocket(port);
LOGGER.info("HTTP/2 TCP Server listening on port " + port);
Expand All @@ -97,8 +98,6 @@ private void runTcpServer(int port) {
sendGoAwayAfterSendingHeadersForASingleStream(outputStream);
} catch (Exception e) {
LOGGER.error(e.getMessage());
} finally {
serverSocket.close();
}
} catch (IOException e) {
LOGGER.error(e.getMessage());
Expand All @@ -118,4 +117,10 @@ private static void sendGoAwayAfterSendingHeadersForASingleStream(OutputStream o
outputStream.write(GO_AWAY_FRAME_STREAM_01);
Thread.sleep(END_SLEEP_TIME);
}

@AfterMethod
public void cleanUp() throws IOException {
h2ClientWithPriorKnowledge.close();
serverSocket.close();
}
}

This file was deleted.

Loading

0 comments on commit 40ded00

Please sign in to comment.