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
Showing
9 changed files
with
196 additions
and
25 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
57 changes: 57 additions & 0 deletions
57
...a/src/test/java/com/linecorp/centraldogma/client/armeria/JsonEndpointListDecoderTest.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 @@ | ||
/* | ||
* Copyright 2018 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.linecorp.centraldogma.client.armeria; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
import com.linecorp.armeria.client.Endpoint; | ||
|
||
public class JsonEndpointListDecoderTest { | ||
private static final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
static List<String> HOST_AND_PORT_LIST = ImmutableList.of( | ||
"centraldogma-sample001.com", | ||
"centraldogma-sample001.com:1234", | ||
"1.2.3.4", | ||
"1.2.3.4:5678" | ||
); | ||
|
||
static List<Endpoint> ENDPOINT_LIST = ImmutableList.of( | ||
Endpoint.of("centraldogma-sample001.com"), | ||
Endpoint.of("centraldogma-sample001.com", 1234), | ||
Endpoint.of("1.2.3.4"), | ||
Endpoint.of("1.2.3.4", 5678) | ||
); | ||
|
||
@Test | ||
public void decode() throws Exception { | ||
EndpointListDecoder<JsonNode> decoder = EndpointListDecoder.JSON; | ||
List<Endpoint> decoded = decoder.decode( | ||
objectMapper.readTree(objectMapper.writeValueAsString(HOST_AND_PORT_LIST))); | ||
|
||
assertThat(decoded).hasSize(4); | ||
assertThat(decoded).isEqualTo(ENDPOINT_LIST); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...a/src/test/java/com/linecorp/centraldogma/client/armeria/TextEndpointListDecoderTest.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,23 @@ | ||
package com.linecorp.centraldogma.client.armeria; | ||
|
||
import static com.linecorp.centraldogma.client.armeria.JsonEndpointListDecoderTest.ENDPOINT_LIST; | ||
import static com.linecorp.centraldogma.client.armeria.JsonEndpointListDecoderTest.HOST_AND_PORT_LIST; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.junit.Test; | ||
|
||
import com.linecorp.armeria.client.Endpoint; | ||
|
||
public class TextEndpointListDecoderTest { | ||
@Test | ||
public void decode() { | ||
EndpointListDecoder<String> decoder = EndpointListDecoder.TEXT; | ||
List<Endpoint> decoded = decoder.decode(HOST_AND_PORT_LIST.stream().collect(Collectors.joining("\n"))); | ||
|
||
assertThat(decoded).hasSize(4); | ||
assertThat(decoded).isEqualTo(ENDPOINT_LIST); | ||
} | ||
} |
19 changes: 0 additions & 19 deletions
19
client/java/src/main/java/com/linecorp/centraldogma/client/armeria/package-info.java
This file was deleted.
Oops, something went wrong.
110 changes: 110 additions & 0 deletions
110
it/src/test/java/com/linecorp/centraldogma/it/CentralDogmaEndpointGroupTest.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,110 @@ | ||
/* | ||
* Copyright 2018 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.linecorp.centraldogma.it; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.stream.Collectors; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
import com.linecorp.armeria.client.Endpoint; | ||
import com.linecorp.centraldogma.client.CentralDogma; | ||
import com.linecorp.centraldogma.client.Watcher; | ||
import com.linecorp.centraldogma.client.armeria.CentralDogmaEndpointGroup; | ||
import com.linecorp.centraldogma.client.armeria.EndpointListDecoder; | ||
import com.linecorp.centraldogma.common.Change; | ||
import com.linecorp.centraldogma.common.Query; | ||
import com.linecorp.centraldogma.common.Revision; | ||
import com.linecorp.centraldogma.testing.CentralDogmaRule; | ||
|
||
public class CentralDogmaEndpointGroupTest { | ||
private static List<String> HOST_AND_PORT_LIST = ImmutableList.of( | ||
"centraldogma-sample001.com:1234", | ||
"1.2.3.4:5678" | ||
); | ||
private static String HOST_AND_PORT_LIST_JSON; | ||
|
||
static { | ||
try { | ||
HOST_AND_PORT_LIST_JSON = new ObjectMapper().writeValueAsString(HOST_AND_PORT_LIST); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static List<Endpoint> ENDPOINT_LIST = ImmutableList.of( | ||
Endpoint.of("centraldogma-sample001.com", 1234), | ||
Endpoint.of("1.2.3.4", 5678) | ||
); | ||
|
||
@Rule | ||
public final CentralDogmaRule dogma = new CentralDogmaRule() { | ||
@Override | ||
protected void scaffold(CentralDogma client) { | ||
client.createProject("directory").join(); | ||
client.createRepository("directory", "my-service").join(); | ||
client.push("directory", "my-service", | ||
Revision.HEAD, "commit", | ||
Change.ofJsonUpsert("/endpoint.json", HOST_AND_PORT_LIST_JSON)) | ||
.join(); | ||
client.push("directory", "my-service", | ||
Revision.HEAD, "commit", | ||
Change.ofTextUpsert("/endpoint.txt", | ||
HOST_AND_PORT_LIST.stream().collect(Collectors.joining("\n")))) | ||
.join(); | ||
} | ||
}; | ||
|
||
@Test | ||
public void json() { | ||
CentralDogmaEndpointGroup<JsonNode> endpointGroup = CentralDogmaEndpointGroup.ofWatcher( | ||
dogma.client().fileWatcher("directory", "my-service", | ||
Query.ofJson("/endpoint.json")), | ||
EndpointListDecoder.JSON); | ||
assertThat(endpointGroup.endpoints()).isEqualTo(ENDPOINT_LIST); | ||
} | ||
|
||
@Test(timeout = 10000) | ||
public void text() throws Exception { | ||
Watcher<String> watcher = dogma.client().fileWatcher("directory", "my-service", | ||
Query.ofText("/endpoint.txt")); | ||
CountDownLatch latch = new CountDownLatch(2); | ||
watcher.watch(unused -> latch.countDown()); | ||
CentralDogmaEndpointGroup<String> endpointGroup = CentralDogmaEndpointGroup.ofWatcher( | ||
watcher, EndpointListDecoder.TEXT); | ||
assertThat(endpointGroup.endpoints()).isEqualTo(ENDPOINT_LIST); | ||
assertThat(latch.getCount()).isOne(); | ||
|
||
dogma.client().push("directory", "my-service", | ||
Revision.HEAD, "commit", | ||
Change.ofTextUpsert("/endpoint.txt", | ||
"foo.bar:1234")) | ||
.join(); | ||
|
||
latch.await(); | ||
assertThat(endpointGroup.endpoints()).isEqualTo(ImmutableList.of(Endpoint.of("foo.bar", 1234))); | ||
} | ||
} |