-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide the fluent API for CentralDogma client (#651)
Motivation: Currently, `CentralDogma` client has a bunch of methods that take a bunch of parameters. It makes it harder to add another optional parameter to the existing methods because we need to add another pair of existing methods. For example: ```java // Existing methods: void watch(String a); void watch(String a, String b); void watch(String a, String b, String c); // If we want to add an optional long value then we need another three methods: void watch(String a, long d); void watch(String a, String b, long d); void watch(String a, String b, String c, long d); ``` Modifications: - Add `PathPattern` interface to pass as the parameter instead of String. - Add `CentralDogma.forRepo(...)` method that returns `CentralDogmaRepository`. - Users can use the instance to send a request: ```java centralDogma.forRepo("foo", "bar").file("/foo.json").get(); centralDogma.forRepo("foo", "bar").watch("/foo.json").start(); centralDogma.forRepo("foo", "bar").watcher(PathPattern.all()).start(); ``` Result: - You can now send a request to the Central Dogma server via fluent APIs. - (Deprecated) Various methods in `CentralDogma` client are deprecated. Use fluent APIs. Co-authored-by: Din <[email protected]>
- Loading branch information
Showing
57 changed files
with
3,414 additions
and
922 deletions.
There are no files selected for viewing
138 changes: 67 additions & 71 deletions
138
...acy/src/main/java/com/linecorp/centraldogma/client/armeria/legacy/LegacyCentralDogma.java
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -54,6 +54,7 @@ | |
import com.linecorp.centraldogma.common.Markup; | ||
import com.linecorp.centraldogma.common.MergeQuery; | ||
import com.linecorp.centraldogma.common.MergeSource; | ||
import com.linecorp.centraldogma.common.PathPattern; | ||
import com.linecorp.centraldogma.common.PushResult; | ||
import com.linecorp.centraldogma.common.Query; | ||
import com.linecorp.centraldogma.common.Revision; | ||
|
@@ -242,7 +243,7 @@ void listFiles() throws Exception { | |
callback.onComplete(ImmutableList.of(entry)); | ||
return null; | ||
}).when(iface).listFiles(anyString(), anyString(), any(), anyString(), any()); | ||
assertThat(client.listFiles("project", "repo", new Revision(1), "/a.txt").get()) | ||
assertThat(client.listFiles("project", "repo", new Revision(1), PathPattern.of("/a.txt")).get()) | ||
.isEqualTo(ImmutableMap.of("/a.txt", EntryType.TEXT)); | ||
verify(iface).listFiles(anyString(), anyString(), any(), anyString(), any()); | ||
} | ||
|
@@ -256,7 +257,7 @@ void getFiles() throws Exception { | |
callback.onComplete(ImmutableList.of(entry)); | ||
return null; | ||
}).when(iface).getFiles(anyString(), anyString(), any(), anyString(), any()); | ||
assertThat(client.getFiles("project", "repo", new Revision(1), "path").get()) | ||
assertThat(client.getFiles("project", "repo", new Revision(1), PathPattern.of("path")).get()) | ||
.isEqualTo(ImmutableMap.of("/b.txt", Entry.ofText(new Revision(1), "/b.txt", "world"))); | ||
verify(iface).getFiles(anyString(), anyString(), any(), anyString(), any()); | ||
} | ||
|
@@ -274,12 +275,13 @@ void getHistory() throws Exception { | |
ImmutableList.of(new TChange("/a.txt", ChangeType.UPSERT_TEXT).setContent("content"))))); | ||
return null; | ||
}).when(iface).getHistory(any(), any(), any(), any(), any(), any()); | ||
assertThat(client.getHistory("project", "repo", new Revision(1), new Revision(3), "path").get()) | ||
assertThat(client.getHistory("project", "repo", new Revision(1), new Revision(3), | ||
PathPattern.of("path")).get()) | ||
.isEqualTo(ImmutableList.of(new Commit(new Revision(1), | ||
new Author("name", "[email protected]"), | ||
Instant.parse(TIMESTAMP).toEpochMilli(), | ||
"summary", "detail", Markup.PLAINTEXT))); | ||
verify(iface).getHistory(eq("project"), eq("repo"), any(), any(), eq("path"), any()); | ||
verify(iface).getHistory(eq("project"), eq("repo"), any(), any(), eq("/**/path"), any()); | ||
} | ||
|
||
@Test | ||
|
@@ -291,9 +293,10 @@ void getDiffs() throws Exception { | |
callback.onComplete(ImmutableList.of(change)); | ||
return null; | ||
}).when(iface).getDiffs(any(), any(), any(), any(), any(), any()); | ||
assertThat(client.getDiffs("project", "repo", new Revision(1), new Revision(3), "path").get()) | ||
assertThat(client.getDiff("project", "repo", new Revision(1), new Revision(3), PathPattern.of("path")) | ||
.get()) | ||
.isEqualTo(ImmutableList.of(Change.ofTextUpsert("/a.txt", "content"))); | ||
verify(iface).getDiffs(eq("project"), eq("repo"), any(), any(), eq("path"), any()); | ||
verify(iface).getDiffs(eq("project"), eq("repo"), any(), any(), eq("/**/path"), any()); | ||
} | ||
|
||
@Test | ||
|
@@ -395,7 +398,8 @@ void watchRepository() throws Exception { | |
callback.onComplete(new WatchRepositoryResult().setRevision(new TRevision(42))); | ||
return null; | ||
}).when(iface).watchRepository(any(), any(), any(), anyString(), anyLong(), any()); | ||
assertThat(client.watchRepository("project", "repo", new Revision(1), "/a.txt", 100).get()) | ||
assertThat(client.watchRepository("project", "repo", new Revision(1), | ||
PathPattern.of("/a.txt"), 100, false).get()) | ||
.isEqualTo(new Revision(42)); | ||
verify(iface).watchRepository(eq("project"), eq("repo"), any(), eq("/a.txt"), eq(100L), any()); | ||
} | ||
|
@@ -407,7 +411,8 @@ void watchRepositoryTimedOut() throws Exception { | |
callback.onComplete(new WatchRepositoryResult()); | ||
return null; | ||
}).when(iface).watchRepository(any(), any(), any(), anyString(), anyLong(), any()); | ||
assertThat(client.watchRepository("project", "repo", new Revision(1), "/a.txt", 100).get()) | ||
assertThat(client.watchRepository("project", "repo", new Revision(1), | ||
PathPattern.of("/a.txt"), 100, false).get()) | ||
.isNull(); | ||
verify(iface).watchRepository(eq("project"), eq("repo"), any(), eq("/a.txt"), eq(100L), any()); | ||
} | ||
|
@@ -421,7 +426,8 @@ void watchFile() throws Exception { | |
.setContent("foo")); | ||
return null; | ||
}).when(iface).watchFile(any(), any(), any(), any(), anyLong(), any()); | ||
assertThat(client.watchFile("project", "repo", new Revision(1), Query.ofText("/a.txt"), 100).get()) | ||
assertThat(client.watchFile("project", "repo", new Revision(1), | ||
Query.ofText("/a.txt"), 100, false).get()) | ||
.isEqualTo(Entry.ofText(new Revision(42), "/a.txt", "foo")); | ||
verify(iface).watchFile(eq("project"), eq("repo"), any(), any(), eq(100L), any()); | ||
} | ||
|
@@ -434,7 +440,7 @@ void watchFileTimedOut() throws Exception { | |
return null; | ||
}).when(iface).watchFile(any(), any(), any(), any(), anyLong(), any()); | ||
assertThat(client.watchFile("project", "repo", new Revision(1), | ||
Query.ofText("/a.txt"), 100).get()).isNull(); | ||
Query.ofText("/a.txt"), 100, false).get()).isNull(); | ||
verify(iface).watchFile(eq("project"), eq("repo"), any(), any(), eq(100L), any()); | ||
} | ||
} |
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
Oops, something went wrong.