Skip to content

Commit

Permalink
refactor: cleanup tests
Browse files Browse the repository at this point in the history
� Conflicts:
�	carapace-server/src/test/java/org/carapaceproxy/backends/RestartEndpointTest.java
NiccoMlt committed Nov 27, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 66234ef commit 275b82c
Showing 18 changed files with 168 additions and 213 deletions.
20 changes: 9 additions & 11 deletions carapace-server/src/test/java/org/carapaceproxy/BigUploadTest.java
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@
*/
package org.carapaceproxy;

import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -33,11 +35,8 @@
import java.util.concurrent.Executors;
import java.util.function.Supplier;
import org.apache.commons.io.IOUtils;
import org.carapaceproxy.core.EndpointKey;
import org.carapaceproxy.core.HttpProxyServer;
import org.carapaceproxy.utils.TestEndpointMapper;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -172,7 +171,6 @@ public void testConnectionResetByPeerDuringWriteToEndpoint() throws Exception {
mockServer.start();

TestEndpointMapper mapper = new TestEndpointMapper("localhost", mockServer.getPort());
EndpointKey key = new EndpointKey("localhost", mockServer.getPort());

int size = 20_000_000;

@@ -203,16 +201,16 @@ public void testConnectionResetByPeerDuringWriteToEndpoint() throws Exception {

@Test
public void testBlockingServerWorks() throws Exception {

try (SimpleBlockingTcpServer mockServer =
new SimpleBlockingTcpServer(() -> {
return new StaticResponseHandler("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nit works!\r\n".getBytes(StandardCharsets.US_ASCII));
})) {

SimpleBlockingTcpServer mockServer = new SimpleBlockingTcpServer(() -> new StaticResponseHandler("""
HTTP/1.1 200 OK\r
Content-Type: text/plain\r
\r
it works!\r
""".getBytes(StandardCharsets.US_ASCII)));
try (mockServer) {
mockServer.start();

TestEndpointMapper mapper = new TestEndpointMapper("localhost", mockServer.getPort());
EndpointKey key = new EndpointKey("localhost", mockServer.getPort());

try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) {
server.start();
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import java.net.URI;
import java.nio.charset.StandardCharsets;
@@ -32,12 +35,8 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.io.IOUtils;
import org.carapaceproxy.core.EndpointKey;
import org.carapaceproxy.core.HttpProxyServer;
import org.carapaceproxy.utils.TestEndpointMapper;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -64,11 +63,10 @@ public void test() throws Exception {
.withBody("it <b>works</b> !!")));

TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port());
EndpointKey key = new EndpointKey("localhost", wireMockRule.port());

int size = 100;
int concurrentClients = 4;
try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) {
try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) {
server.start();
int port = server.getLocalPort();

Original file line number Diff line number Diff line change
@@ -19,17 +19,18 @@
under the License.
*/

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import org.carapaceproxy.core.HttpProxyServer;
import java.util.Properties;
import org.carapaceproxy.configstore.HerdDBConfigurationStore;
import org.carapaceproxy.configstore.PropertiesConfigurationStore;
import org.carapaceproxy.core.HttpProxyServer;
import org.carapaceproxy.server.filters.RegexpMapUserIdFilter;
import org.carapaceproxy.server.filters.XForwardedForRequestFilter;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
Loading

0 comments on commit 275b82c

Please sign in to comment.