@Override protected PushResult doBackward(Commit commit) { return new PushResult(RevisionConverter.TO_MODEL.convert(commit.getRevision()), Instant.parse(commit.getTimestamp()).toEpochMilli()); } }
/** * Returns the time and date of the pushed commit in * <a href="https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations">ISO 8601 * combined date and time representation</a>. */ public String whenAsText() { if (whenAsText == null) { whenAsText = DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(when())); } return whenAsText; }
@Override public String toString() { return MoreObjects.toStringHelper(this) .addValue(revision.text()) .add("when", whenAsText()) .toString(); } }
@Test public void testDiff_rename() throws Exception { final CentralDogma client = rule.client(); final Revision rev1 = client.push(rule.project(), rule.repo1(), HEAD, "summary1", Change.ofTextUpsert("/bar.txt", "hello")).join().revision(); final Revision rev2 = client.push(rule.project(), rule.repo1(), HEAD, "summary2", Change.ofRename("/bar.txt", "/baz.txt")).join().revision(); assertThat(rev1.forward(1)).isEqualTo(rev2); assertThat(client.getDiff(rule.project(), rule.repo1(), rev1, rev2, Query.ofText("/bar.txt")).join()) .isEqualTo(Change.ofRemoval("/bar.txt")); } }
@Test public void testWatchRepository() throws Exception { final Revision rev1 = rule.client() .normalizeRevision(rule.project(), rule.repo1(), Revision.HEAD) .join(); final CompletableFuture<Revision> future = rule.client().watchRepository(rule.project(), rule.repo1(), rev1, "/**", 3000); assertThatThrownBy(() -> future.get(500, TimeUnit.MILLISECONDS)).isInstanceOf(TimeoutException.class); final Change<JsonNode> change = Change.ofJsonUpsert("/test/test3.json", "[ 3, 2, 1 ]"); final PushResult result = rule.client().push( rule.project(), rule.repo1(), rev1, "Add test3.json", change).join(); final Revision rev2 = result.revision(); assertThat(rev2).isEqualTo(rev1.forward(1)); assertThat(future.get(3, TimeUnit.SECONDS)).isEqualTo(rev2); }
/** * Returns the time and date of the pushed commit in * <a href="https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations">ISO 8601 * combined date and time representation</a>. */ public String whenAsText() { if (whenAsText == null) { whenAsText = DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(when())); } return whenAsText; }
@Override public String toString() { return MoreObjects.toStringHelper(this) .addValue(revision.text()) .add("when", whenAsText()) .toString(); } }
@Override protected PushResult doBackward(Commit commit) { return new PushResult(RevisionConverter.TO_MODEL.convert(commit.getRevision()), Instant.parse(commit.getTimestamp()).toEpochMilli()); } }
@Test public void history() throws Exception { final String project = testName.getMethodName(); final CentralDogma client = rule.client(); client.createProject(project).join(); client.createRepository(project, REPO_FOO).join(); final PushResult res1 = client.push(project, REPO_FOO, HEAD, "Add a file", Change.ofTextUpsert("/foo.txt", "bar")).join(); final CacheStats stats1 = cacheStatsSupplier.get(); // Get the history in various combination of from/to revisions. final List<Commit> history1 = client.getHistory(project, REPO_FOO, HEAD, new Revision(-2), "/**").join(); final List<Commit> history2 = client.getHistory(project, REPO_FOO, HEAD, INIT, "/**").join(); final List<Commit> history3 = client.getHistory(project, REPO_FOO, res1.revision(), new Revision(-2), "/**").join(); final List<Commit> history4 = client.getHistory(project, REPO_FOO, res1.revision(), INIT, "/**").join(); // and they should all same. assertThat(history1).isEqualTo(history2); assertThat(history1).isEqualTo(history3); assertThat(history1).isEqualTo(history4); final CacheStats stats2 = cacheStatsSupplier.get(); // Should miss once and hit 3 times. assertThat(stats2.missCount()).isEqualTo(stats1.missCount() + 1); assertThat(stats2.hitCount()).isEqualTo(stats1.hitCount() + 3); }
/** * Returns the time and date of the pushed commit in * <a href="https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations">ISO 8601 * combined date and time representation</a>. */ public String whenAsText() { if (whenAsText == null) { whenAsText = DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(when())); } return whenAsText; }
@Override public String toString() { return MoreObjects.toStringHelper(this) .addValue(revision.text()) .add("when", whenAsText()) .toString(); } }
@Test public void push() throws Exception { doAnswer(invocation -> { final AsyncMethodCallback<TCommit> callback = invocation.getArgument(7); callback.onComplete(new TCommit( new TRevision(1), new TAuthor("name", "name@sample.com"), TIMESTAMP, "summary", new Comment("detail"), ImmutableList.of())); return null; }).when(iface).push(anyString(), anyString(), any(), any(), any(), any(), any(), any()); assertThat(client.push("project", "repo", new Revision(1), new Author("name", "name@sample.com"), "summary", "detail", Markup.PLAINTEXT, ImmutableList.of(Change.ofTextUpsert("/a.txt", "hello")) ).get()).isEqualTo(new PushResult(new Revision(1), Instant.parse(TIMESTAMP).toEpochMilli())); verify(iface).push(eq("project"), eq("repo"), any(), any(), eq("summary"), any(), any(), any()); }
final Entry<?> cachedEntry1 = client.getFile(project, REPO_FOO, res.revision(), query).join(); final Entry<?> cachedEntry2 = client.getFile(project, REPO_FOO, HEAD, query).join();
@Test public void testDiff_remove() throws Exception { final CentralDogma client = rule.client(); final Revision rev1 = client.push(rule.project(), rule.repo1(), HEAD, "summary1", Change.ofTextUpsert("/foo.txt", "hello")).join().revision(); final Revision rev2 = client.push(rule.project(), rule.repo1(), HEAD, "summary2", Change.ofRemoval("/foo.txt")).join().revision(); assertThat(rev1.forward(1)).isEqualTo(rev2); assertThat(client.getDiff(rule.project(), rule.repo1(), rev1, rev1, Query.ofText("/foo.txt")).join().type()) .isEqualTo(ChangeType.APPLY_TEXT_PATCH); assertThat(client.getDiff(rule.project(), rule.repo1(), rev1, rev2, Query.ofText("/foo.txt")).join()) .isEqualTo(Change.ofRemoval("/foo.txt")); }
@Test public void testWatchFileWithIdentityQuery() throws Exception { final Revision rev0 = rule.client() .normalizeRevision(rule.project(), rule.repo1(), Revision.HEAD) .join(); final CompletableFuture<Entry<JsonNode>> future = rule.client().watchFile( rule.project(), rule.repo1(), rev0, Query.ofJson("/test/test1.json"), 3000); assertThatThrownBy(() -> future.get(500, TimeUnit.MILLISECONDS)).isInstanceOf(TimeoutException.class); // An irrelevant change should not trigger a notification. final Change<JsonNode> change1 = Change.ofJsonUpsert("/test/test2.json", "[ 3, 2, 1 ]"); final PushResult res1 = rule.client().push( rule.project(), rule.repo1(), rev0, "Add test2.json", change1).join(); final Revision rev1 = res1.revision(); assertThatThrownBy(() -> future.get(500, TimeUnit.MILLISECONDS)).isInstanceOf(TimeoutException.class); // Make a relevant change now. final Change<JsonNode> change2 = Change.ofJsonUpsert("/test/test1.json", "[ -1, -2, -3 ]"); final PushResult res2 = rule.client().push( rule.project(), rule.repo1(), rev1, "Update test1.json", change2).join(); final Revision rev2 = res2.revision(); assertThat(rev2).isEqualTo(rev0.forward(2)); assertThat(future.get(3, TimeUnit.SECONDS)).isEqualTo( Entry.ofJson(rev2, "/test/test1.json", "[-1,-2,-3]")); }
@Test public void testWatchFile() throws Exception { final Revision rev0 = rule.client() .normalizeRevision(rule.project(), rule.repo1(), Revision.HEAD) .join(); final CompletableFuture<Entry<JsonNode>> future = rule.client().watchFile(rule.project(), rule.repo1(), rev0, Query.ofJsonPath("/test/test1.json", "$[0]"), 3000); assertThatThrownBy(() -> future.get(500, TimeUnit.MILLISECONDS)).isInstanceOf(TimeoutException.class); // An irrelevant change should not trigger a notification. final Change<JsonNode> change1 = Change.ofJsonUpsert("/test/test2.json", "[ 3, 2, 1 ]"); final PushResult res1 = rule.client().push( rule.project(), rule.repo1(), rev0, "Add test2.json", change1).join(); final Revision rev1 = res1.revision(); assertThatThrownBy(() -> future.get(500, TimeUnit.MILLISECONDS)).isInstanceOf(TimeoutException.class); // Make a relevant change now. final Change<JsonNode> change2 = Change.ofJsonUpsert("/test/test1.json", "[ -1, -2, -3 ]"); final PushResult res2 = rule.client().push( rule.project(), rule.repo1(), rev1, "Add test1.json", change2).join(); final Revision rev2 = res2.revision(); assertThat(rev2).isEqualTo(rev0.forward(2)); assertThat(future.get(3, TimeUnit.SECONDS)).isEqualTo( Entry.ofJson(rev2, "/test/test1.json", "-1")); }