Skip to content

Commit 03a6ab2

Browse files
author
ehennum
committed
remove 8012 ping and check for rest user #1126
1 parent 7a630da commit 03a6ab2

File tree

2 files changed

+45
-26
lines changed

2 files changed

+45
-26
lines changed

ml-development-tools/src/test/java/com/marklogic/client/test/dbfunction/DBFunctionTestUtil.java

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,36 +37,41 @@ private static DatabaseClient makeAdminTestClient() {
3737
);
3838
}
3939
private static DatabaseClient makeRestClientImpl(DatabaseClientFactory.DigestAuthContext auth) {
40-
return makeClientImpl(auth, "8012");
40+
return makeClientImpl(auth, "8012", false);
4141
}
4242
private static DatabaseClient makeTestClientImpl(DatabaseClientFactory.DigestAuthContext auth) {
43-
return makeClientImpl(auth, "8016");
43+
return makeClientImpl(auth, "8016", true);
4444
}
45-
private static DatabaseClient makeClientImpl(DatabaseClientFactory.DigestAuthContext auth, String defaultPort) {
45+
private static DatabaseClient makeClientImpl(
46+
DatabaseClientFactory.DigestAuthContext auth, String defaultPort, boolean withCheck
47+
) {
4648
String host = System.getProperty("TEST_HOST", "localhost");
4749
int port = Integer.parseInt(System.getProperty("TEST_PORT", defaultPort));
4850

4951
DatabaseClient db = DatabaseClientFactory.newClient(host, port, auth);
5052

51-
try {
52-
OkHttpClient client = (OkHttpClient) db.getClientImplementation();
53+
if (withCheck) {
54+
try {
55+
OkHttpClient client = (OkHttpClient) db.getClientImplementation();
5356
// TODO: better alternative to ping for non-REST server
54-
Response response = client.newCall(new Request.Builder().url(
55-
new HttpUrl.Builder()
56-
.scheme("http")
57-
.host(host)
58-
.port(port)
59-
.encodedPath("/")
60-
.build()
61-
).build()
57+
Response response = client.newCall(new Request.Builder().url(
58+
new HttpUrl.Builder()
59+
.scheme("http")
60+
.host(host)
61+
.port(port)
62+
.encodedPath("/")
63+
.build()
64+
).build()
6265
).execute();
63-
int statusCode = response.code();
64-
if (statusCode >= 300 && statusCode != 404) {
65-
throw new RuntimeException(statusCode+" "+response.message());
66+
int statusCode = response.code();
67+
if (statusCode >= 300 && statusCode != 404) {
68+
throw new RuntimeException(statusCode+" "+response.message());
69+
}
70+
} catch (IOException e) {
71+
throw new RuntimeException(e);
6672
}
67-
} catch (IOException e) {
68-
throw new RuntimeException(e);
6973
}
74+
7075
return db;
7176
}
7277
public static URL getResource(String name) {

ml-development-tools/src/test/kotlin/com/marklogic/client/test/dbfunction/fntestconf.kt

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,16 @@ fun setupServer(serializer: ObjectWriter) {
8080
}
8181

8282
val userName = "rest-reader"
83-
createEntity(
84-
client, serializer, "users", "user", userName,
85-
mapOf<String,Any>(
86-
"user-name" to userName,
87-
"password" to "x",
88-
"role" to listOf<String>(userName)
89-
)
90-
)
83+
if (!existsEntity(client, "users", "user", userName)) {
84+
createEntity(
85+
client, serializer, "users", "user", userName,
86+
mapOf<String,Any>(
87+
"user-name" to userName,
88+
"password" to "x",
89+
"role" to listOf<String>(userName)
90+
)
91+
)
92+
}
9193

9294
createEntity(
9395
client, serializer, "servers?group-id=Default&server-type=http", "appserver", serverName,
@@ -102,6 +104,18 @@ fun setupServer(serializer: ObjectWriter) {
102104

103105
dbClient.release()
104106
}
107+
fun existsEntity(client: OkHttpClient, address: String, name: String, instanceName: String) : Boolean {
108+
val response = client.newCall(
109+
Request.Builder()
110+
.url("""http://${host}:8002/manage/v2/${address}/${instanceName}""")
111+
.get()
112+
.build()
113+
).execute()
114+
val status = response.code()
115+
if (status < 400) return true
116+
if (status == 404) return false
117+
throw RuntimeException("""Could not create ${instanceName} ${name}: ${status}""")
118+
}
105119
fun createEntity(client: OkHttpClient, serializer: ObjectWriter, address: String, name: String,
106120
instanceName: String, instancedef: Map<String,Any>) {
107121
val response = client.newCall(

0 commit comments

Comments
 (0)