This repository has been archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fe982c
commit 929274e
Showing
48 changed files
with
3,124 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
build: | ||
./gradlew jar | ||
|
||
clean: | ||
./gradlew clean | ||
|
||
test: | ||
./gradlew test | ||
|
||
TEMP_TEST_OUTPUT=/tmp/sdk-test-service.log | ||
|
||
build-contract-tests: | ||
@cd contract-tests && ../gradlew installDist | ||
|
||
start-contract-test-service: | ||
@contract-tests/service/build/install/service/bin/service | ||
|
||
start-contract-test-service-bg: | ||
@echo "Test service output will be captured in $(TEMP_TEST_OUTPUT)" | ||
@make start-contract-test-service >$(TEMP_TEST_OUTPUT) 2>&1 & | ||
|
||
run-contract-tests: | ||
@curl -s https://raw.githubusercontent.com/launchdarkly/sdk-test-harness/v1.0.0/downloader/run.sh \ | ||
| VERSION=v1 PARAMS="-url http://localhost:8000 -debug -stop-service-at-end $(TEST_HARNESS_PARAMS)" sh | ||
|
||
contract-tests: build-contract-tests start-contract-test-service-bg run-contract-tests | ||
|
||
.PHONY: build-contract-tests start-contract-test-service start-contract-test-service-bg run-contract-tests contract-tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# SDK contract test service | ||
|
||
This directory contains an implementation of the cross-platform SDK testing protocol defined by https://github.com/launchdarkly/sdk-test-harness. See that project's `README` for details of this protocol, and the kinds of SDK capabilities that are relevant to the contract tests. This code should not need to be updated unless the SDK has added or removed such capabilities. | ||
|
||
To run these tests locally, run `make contract-tests` from the SDK project root directory. This downloads the correct version of the test harness tool automatically. | ||
|
||
Or, to test against an in-progress local version of the test harness, run `make start-contract-test-service` from the SDK project root directory; then, in the root directory of the `sdk-test-harness` project, build the test harness and run it from the command line. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
gnsp.disableApplyOnlyOnRootProjectEnforcement=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
plugins { | ||
id "java" | ||
id "application" | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
maven { url "https://oss.sonatype.org/content/groups/public/" } | ||
} | ||
|
||
allprojects { | ||
sourceCompatibility = 1.8 | ||
targetCompatibility = 1.8 | ||
} | ||
|
||
archivesBaseName = "java-sdk-test-service" | ||
|
||
application { | ||
mainClassName = "sdktest.TestService" | ||
} | ||
|
||
ext.versions = [ | ||
"gson": "2.7", | ||
"logback": "1.1.3", | ||
"okhttp": "4.5.0", | ||
"testHelpers": "1.1.0" | ||
] | ||
|
||
configurations { | ||
deps.extendsFrom(implementation) | ||
} | ||
|
||
dependencies { | ||
implementation project(":sdk") | ||
implementation "ch.qos.logback:logback-classic:${versions.logback}" | ||
implementation "com.google.code.gson:gson:${versions.gson}" | ||
implementation "com.squareup.okhttp3:okhttp:${versions.okhttp}" | ||
implementation "com.launchdarkly:test-helpers:${versions.testHelpers}" | ||
} |
Empty file.
52 changes: 52 additions & 0 deletions
52
contract-tests/service/src/main/java/sdktest/BigSegmentStoreFixture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package sdktest; | ||
|
||
import com.launchdarkly.sdk.server.interfaces.BigSegmentStore; | ||
import com.launchdarkly.sdk.server.interfaces.BigSegmentStoreFactory; | ||
import com.launchdarkly.sdk.server.interfaces.BigSegmentStoreTypes.Membership; | ||
import com.launchdarkly.sdk.server.interfaces.BigSegmentStoreTypes.StoreMetadata; | ||
import com.launchdarkly.sdk.server.interfaces.ClientContext; | ||
|
||
import java.io.IOException; | ||
|
||
import sdktest.CallbackRepresentations.BigSegmentStoreGetMembershipParams; | ||
import sdktest.CallbackRepresentations.BigSegmentStoreGetMembershipResponse; | ||
import sdktest.CallbackRepresentations.BigSegmentStoreGetMetadataResponse; | ||
|
||
public class BigSegmentStoreFixture implements BigSegmentStore, BigSegmentStoreFactory { | ||
private final CallbackService service; | ||
|
||
public BigSegmentStoreFixture(CallbackService service) { | ||
this.service = service; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
service.close(); | ||
} | ||
|
||
@Override | ||
public Membership getMembership(String userHash) { | ||
BigSegmentStoreGetMembershipParams params = new BigSegmentStoreGetMembershipParams(); | ||
params.userHash = userHash; | ||
BigSegmentStoreGetMembershipResponse resp = | ||
service.post("/getMembership", params, BigSegmentStoreGetMembershipResponse.class); | ||
return new Membership() { | ||
@Override | ||
public Boolean checkMembership(String segmentRef) { | ||
return resp.values == null ? null : resp.values.get(segmentRef); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public StoreMetadata getMetadata() { | ||
BigSegmentStoreGetMetadataResponse resp = | ||
service.post("/getMetadata", null, BigSegmentStoreGetMetadataResponse.class); | ||
return new StoreMetadata(resp.lastUpToDate); | ||
} | ||
|
||
@Override | ||
public BigSegmentStore createBigSegmentStore(ClientContext context) { | ||
return this; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
contract-tests/service/src/main/java/sdktest/CallbackRepresentations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package sdktest; | ||
|
||
import java.util.Map; | ||
|
||
public abstract class CallbackRepresentations { | ||
public static class BigSegmentStoreGetMetadataResponse { | ||
Long lastUpToDate; | ||
} | ||
|
||
public static class BigSegmentStoreGetMembershipParams { | ||
String userHash; | ||
} | ||
|
||
public static class BigSegmentStoreGetMembershipResponse { | ||
Map<String, Boolean> values; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
contract-tests/service/src/main/java/sdktest/CallbackService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package sdktest; | ||
|
||
import java.net.URI; | ||
|
||
import okhttp3.MediaType; | ||
import okhttp3.Request; | ||
import okhttp3.RequestBody; | ||
import okhttp3.Response; | ||
|
||
public class CallbackService { | ||
private final URI baseUri; | ||
|
||
public CallbackService(URI baseUri) { | ||
this.baseUri = baseUri; | ||
} | ||
|
||
public void close() { | ||
try { | ||
Request request = new Request.Builder().url(baseUri.toURL()).method("DELETE", null).build(); | ||
Response response = TestService.client.newCall(request).execute(); | ||
assertOk(response, ""); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); // all errors are unexpected here | ||
} | ||
} | ||
|
||
public <T> T post(String path, Object params, Class<T> responseClass) { | ||
try { | ||
String uri = baseUri.toString() + path; | ||
RequestBody body = RequestBody.create( | ||
TestService.gson.toJson(params == null ? "{}" : params), | ||
MediaType.parse("application/json")); | ||
Request request = new Request.Builder().url(uri). | ||
method("POST", body).build(); | ||
Response response = TestService.client.newCall(request).execute(); | ||
assertOk(response, path); | ||
if (responseClass == null) { | ||
return null; | ||
} | ||
return TestService.gson.fromJson(response.body().string(), responseClass); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); // all errors are unexpected here | ||
} | ||
} | ||
|
||
private void assertOk(Response response, String path) { | ||
if (!response.isSuccessful()) { | ||
String body = ""; | ||
if (response.body() != null) { | ||
try { | ||
body = ": " + response.body().string(); | ||
} catch (Exception e) {} | ||
} | ||
throw new RuntimeException("HTTP error " + response.code() + " from callback to " + baseUri + path + body); | ||
} | ||
} | ||
} |
Oops, something went wrong.