Skip to content

Commit

Permalink
refactor Http Endpoint class URL to URI for better usablility with Ht…
Browse files Browse the repository at this point in the history
…tpClients
  • Loading branch information
AayuStark007 committed Jun 23, 2024
1 parent 9f552e2 commit b465499
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public HttpMessageDelivery(Endpoint.HttpEndpoint endpoint, HttpClient client) {
@Override
public CompletableFuture<DeliveryResponse> deliver(Message message) throws Exception {
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
.uri(endpoint.getUrl().toURI())
.uri(endpoint.getUri())
.timeout(Duration.ofMillis(endpoint.getRequestTimeoutMs()))
.header("Content-Type", endpoint.getContentType())
.method(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.net.URL;
import java.net.URI;

@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
Expand All @@ -29,7 +29,7 @@ public enum Protocol {
@EqualsAndHashCode(callSuper = true)
@Data
public static final class HttpEndpoint extends Endpoint {
private final URL url;
private final URI uri;
private final String method;
private final String contentType;
private final long connectTimeoutMs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.junit.jupiter.api.extension.ExtendWith;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.util.List;
import java.util.concurrent.CompletableFuture;

Expand Down Expand Up @@ -115,11 +115,7 @@ void testSubscriptionEntitiesSerDe() {
1, 1, 1, 1
);
ConsumptionPolicy consumptionPolicy = new ConsumptionPolicy(1, 1, false, 1, null);
try {
endpoint = new Endpoint.HttpEndpoint(new URL("http", "localhost", "hello"), "GET", "", 500, 500, false);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
endpoint = new Endpoint.HttpEndpoint(URI.create("http://localhost:8080"), "GET", "", 500, 500, false);
TopicCapacityPolicy capacity = Constants.DefaultTopicCapacity;

String region = "default";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.flipkart.varadhi.web.admin;

import com.flipkart.varadhi.services.VaradhiTopicService;
import com.flipkart.varadhi.entities.*;
import com.flipkart.varadhi.exceptions.ResourceNotFoundException;
import com.flipkart.varadhi.services.ProjectService;
import com.flipkart.varadhi.services.SubscriptionService;
import com.flipkart.varadhi.services.VaradhiTopicService;
import com.flipkart.varadhi.utils.VaradhiSubscriptionFactory;
import com.flipkart.varadhi.web.ErrorResponse;
import com.flipkart.varadhi.web.WebTestBase;
Expand All @@ -18,8 +18,7 @@
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
Expand All @@ -29,7 +28,8 @@
import static org.mockito.Mockito.*;

public class SubscriptionHandlersTest extends WebTestBase {
private static final Endpoint endpoint;
private static final Endpoint endpoint =
new Endpoint.HttpEndpoint(URI.create("http://localhost:8080"), "GET", "", 500, 500, false);
private static final RetryPolicy retryPolicy = new RetryPolicy(
new CodeRange[]{new CodeRange(500, 502)},
RetryPolicy.BackoffType.LINEAR,
Expand All @@ -39,14 +39,6 @@ public class SubscriptionHandlersTest extends WebTestBase {
private static final TopicCapacityPolicy capacityPolicy = new TopicCapacityPolicy(1, 10, 1);
private static final SubscriptionShards shards = new SubscriptionUnitShard(0, capacityPolicy, null, null, null);

static {
try {
endpoint = new Endpoint.HttpEndpoint(new URL("http", "localhost", "hello"), "GET", "", 500, 500, false);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}

private final Project project = new Project("project1", 0, "", "team1", "org1");
private final TopicResource topicResource = new TopicResource("topic1", 0, "project2", false, null);
SubscriptionHandlers subscriptionHandlers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,22 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.util.List;

import static com.flipkart.varadhi.entities.VersionedEntity.INITIAL_VERSION;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class SubscriptionTests extends E2EBase {

private static final Endpoint endpoint;
private static final Endpoint endpoint =
new Endpoint.HttpEndpoint(URI.create("http://localhost:8080"), "GET", "", 500, 500, false);
private static Org o1;
private static Team o1t1;
private static Project o1t1p1;
private static TopicResource p1t1;
private static TopicResource p1t2;

static {
try {
endpoint = new Endpoint.HttpEndpoint(new URL("http", "localhost", "hello"), "GET", "", 500, 500, false);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}

private final RetryPolicy retryPolicy = new RetryPolicy(
new CodeRange[]{new CodeRange(500, 502)},
RetryPolicy.BackoffType.LINEAR,
Expand Down

0 comments on commit b465499

Please sign in to comment.