Skip to content

Commit

Permalink
Fix WatchJson5 test
Browse files Browse the repository at this point in the history
  • Loading branch information
ks-yim committed Feb 2, 2022
1 parent a3c3e64 commit 3a818e7
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions it/src/test/java/com/linecorp/centraldogma/it/WatchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.linecorp.centraldogma.it;

import static com.linecorp.centraldogma.it.TestConstants.JSON5_CONTENTS;
import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand All @@ -41,7 +40,6 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.TextNode;

Expand All @@ -59,7 +57,6 @@
import com.linecorp.centraldogma.common.PushResult;
import com.linecorp.centraldogma.common.Query;
import com.linecorp.centraldogma.common.Revision;
import com.linecorp.centraldogma.internal.Json5;

class WatchTest {

Expand Down Expand Up @@ -783,17 +780,22 @@ class WatchJson5Test {
void watchJson5() throws Exception {
final CentralDogma client = dogma.client();

client.forRepo(dogma.project(), dogma.repo1())
.commit("Add foo.json5", Change.ofJsonUpsert("/test/foo.json5", "{a: 'b'}"))
.push(Revision.HEAD)
.join();

final CompletableFuture<Entry<JsonNode>> future =
client.forRepo(dogma.project(), dogma.repo1())
.watch(Query.ofJson("/test/test1.json5"))
.watch(Query.ofJson("/test/foo.json5"))
.start(Revision.HEAD);

assertThatThrownBy(() -> future.get(500, TimeUnit.MILLISECONDS))
.isInstanceOf(TimeoutException.class);

// Make change to an irrelevant file.
client.forRepo(dogma.project(), dogma.repo1())
.commit("Edit foo.json", Change.ofJsonUpsert("/test/foo.json", "{}"))
.commit("Add bar.json5", Change.ofJsonUpsert("/test/bar.json5", "{}"))
.push(Revision.HEAD)
.join();

Expand All @@ -803,30 +805,32 @@ void watchJson5() throws Exception {
// Make change to a relevant file.
final PushResult result =
client.forRepo(dogma.project(), dogma.repo1())
.commit("Edit test1.json5", Change.ofJsonUpsert("/test/test1.json5", "{a: 'foo'}"))
.commit("Edit foo.json5", Change.ofJsonUpsert("/test/foo.json5", "{a: 'foo'}"))
.push(Revision.HEAD)
.join();

assertThat(future.get(3, TimeUnit.SECONDS)).isEqualTo(
Entry.ofJson(result.revision(), "/test/test1.json5", "{a: 'foo'}\n"));
Entry.ofJson(result.revision(), "/test/foo.json5", "{a: 'foo'}\n"));
}

@Test
void watchJson5_notNotifiedIfJsonContentNotChanged() throws JsonParseException {
void watchJson5_notNotifiedIfJsonContentNotChanged() {
final CentralDogma client = dogma.client();

client.forRepo(dogma.project(), dogma.repo1())
.commit("Add bar.json5", Change.ofJsonUpsert("/test/bar.json5", "{a: 'b'}"))
.push(Revision.HEAD)
.join();

final CompletableFuture<Entry<JsonNode>> future =
client.forRepo(dogma.project(), dogma.repo1())
.watch(Query.ofJson("/test/test1.json5"))
.watch(Query.ofJson("/test/bar.json5"))
.start(Revision.HEAD);

// Edit file to the plain JSON, so it doesn't change the actual JSON content in it.
final JsonNode plainJson = Json5.readTree(JSON5_CONTENTS);
client.forRepo(dogma.project(), dogma.repo1())
.commit("Edit test1.json5",
Change.ofJsonUpsert("/test/test1.json5", plainJson))
.push(Revision.HEAD)
.join();
client.forRepo(dogma.project(), dogma.repo1())
.commit("Edit bar.json5", Change.ofJsonUpsert("/test/bar.json5", "{\"a\": \"b\"}"))
.push(Revision.HEAD)
.join();

// Watcher should not be notified since the JSON content is still the same.
assertThatThrownBy(() -> future.get(1000, TimeUnit.MILLISECONDS))
Expand Down

0 comments on commit 3a818e7

Please sign in to comment.