@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); }
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 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); }
@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")); }