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

feat: introduce setDataPlaneUrl and mark endPoint as deprecated #45

Merged
merged 3 commits into from
Dec 19, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- [New](https://github.com/rudderlabs/rudder-sdk-java/pull/43) Add CI feature
- [New](https://github.com/rudderlabs/rudder-sdk-java/pull/41) Add support for channel object in individual payload
- [New](https://github.com/rudderlabs/rudder-sdk-java/pull/38) Add library info into the context object at each individual message
- [New](https://github.com/rudderlabs/rudder-sdk-java/pull/45) Introduce setDataPlaneUrl and mark endPoint as deprecated
- [Breaking change](https://github.com/rudderlabs/rudder-sdk-java/pull/42) Bundle the gzip support inside the core SDK

- [Chore] Dependency upgrades
Expand Down
2 changes: 1 addition & 1 deletion analytics-sample/src/main/java/sample/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void main(String... args) throws Exception {
// https://rudder.com/rudder-engineering/sources/test-java/debugger
final RudderAnalytics analytics =
RudderAnalytics.builder("write_key")
.endpoint("data_plane_url")
.setDataPlaneUrl("data_plane_url")
.plugin(blockingFlush.plugin())
.plugin(new LoggingPlugin())
.client(createClient())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static class Builder {
private final String writeKey;
private OkHttpClient client;
private Log log;
public HttpUrl endpoint;
@Deprecated public HttpUrl endpoint;
public HttpUrl uploadURL;
private String userAgent = DEFAULT_USER_AGENT;
private List<MessageTransformer> messageTransformers;
Expand Down Expand Up @@ -184,15 +184,25 @@ public Builder log(Log log) {
/**
* Set an endpoint (host only) that this client should upload events to. Uses {@code
* http://hosted.rudderlabs.com} by default.
*
* &#064;Deprecated use {@link #setDataPlaneUrl(String)}
*/
@Deprecated
public Builder endpoint(String endpoint) {
if (endpoint == null || endpoint.trim().length() == 0) {
throw new NullPointerException("endpoint cannot be null or empty.");
return setDataPlaneUrl(endpoint);
}

/**
* Set a dataPlaneUrl that this client should upload events to.
*/
public Builder setDataPlaneUrl(String dataPlaneUrl) {
if (dataPlaneUrl == null || dataPlaneUrl.trim().length() == 0) {
throw new NullPointerException("dataPlaneUrl cannot be null or empty.");
}
if (! endpoint.endsWith("/")){
endpoint += "/";
if (! dataPlaneUrl.endsWith("/")){
dataPlaneUrl += "/";
}
this.endpoint = HttpUrl.parse(endpoint + DEFAULT_PATH);
this.endpoint = HttpUrl.parse(dataPlaneUrl + DEFAULT_PATH);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public void nullEndpoint() {
builder.endpoint(null);
fail("Should fail for null endpoint");
} catch (NullPointerException e) {
assertThat(e).hasMessage("endpoint cannot be null or empty.");
assertThat(e).hasMessage("dataPlaneUrl cannot be null or empty.");
}
}

Expand All @@ -253,14 +253,31 @@ public void emptyEndpoint() {
builder.endpoint("");
fail("Should fail for empty endpoint");
} catch (NullPointerException e) {
assertThat(e).hasMessage("endpoint cannot be null or empty.");
assertThat(e).hasMessage("dataPlaneUrl cannot be null or empty.");
}

try {
builder.endpoint(" ");
fail("Should fail for empty endpoint");
} catch (NullPointerException e) {
assertThat(e).hasMessage("endpoint cannot be null or empty.");
assertThat(e).hasMessage("dataPlaneUrl cannot be null or empty.");
}
}

@Test
public void emptyDataPlaneUrl() {
try {
builder.setDataPlaneUrl("");
fail("Should fail for empty dataPlaneUrl");
} catch (NullPointerException e) {
assertThat(e).hasMessage("dataPlaneUrl cannot be null or empty.");
}

try {
builder.setDataPlaneUrl(" ");
fail("Should fail for empty dataPlaneUrl");
} catch (NullPointerException e) {
assertThat(e).hasMessage("dataPlaneUrl cannot be null or empty.");
}
}

Expand All @@ -270,13 +287,26 @@ public void buildsWithValidEndpoint() {
assertThat(analytics).isNotNull();
}

@Test
public void buildsWithValidDataPlaneUrl() {
RudderAnalytics analytics = builder.setDataPlaneUrl("https://hosted.rudderlabs.com").build();
assertThat(analytics).isNotNull();
}

@Test
public void buildsCorrectEndpoint() {
builder.endpoint("https://hosted.rudderlabs.com");
String expectedURL = "https://hosted.rudderlabs.com/v1/batch";
assertEquals(expectedURL, builder.endpoint.toString());
}

@Test
public void buildsCorrectDataPlaneUrl() {
builder.setDataPlaneUrl("https://hosted.rudderlabs.com");
String expectedURL = "https://hosted.rudderlabs.com/v1/batch";
assertEquals(expectedURL, builder.endpoint.toString());
}

@Test
public void buildsWithValidUploadURL() {
RudderAnalytics analytics = builder.setUploadURL("https://example.com/v2/batch/").build();
Expand Down