Skip to content

Commit 3db6826

Browse files
committed
NO-ISSUE fix test
1 parent 37bb1f3 commit 3db6826

File tree

4 files changed

+54
-66
lines changed

4 files changed

+54
-66
lines changed

centraldogma/.DS_Store

6 KB
Binary file not shown.

centraldogma/src/main/java/com/linecorp/decaton/centraldogma/CentralDogmaPropertySupplier.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
import com.linecorp.decaton.processor.runtime.PropertyDefinition;
4848
import com.linecorp.decaton.processor.runtime.PropertySupplier;
4949

50+
import static com.linecorp.decaton.processor.runtime.ProcessorProperties.PROPERTY_DEFINITIONS;
51+
5052
/**
5153
* A {@link PropertySupplier} implementation with Central Dogma backend.
5254
* <p>
@@ -119,18 +121,18 @@ public CentralDogmaPropertySupplier(CentralDogmaRepository centralDogmaRepositor
119121
}
120122

121123
rootWatcher.watch(node -> {
122-
node.fields().forEachRemaining(entry -> {
123-
DynamicProperty<?> p = cachedProperties.get(entry.getKey());
124-
if (p != null) {
124+
for (PropertyDefinition<?> definition : PROPERTY_DEFINITIONS) {
125+
DynamicProperty<?> p = cachedProperties.get(definition.name());
126+
if (p != null && node.has(definition.name())) {
125127
try {
126-
setValue(p, entry.getValue());
128+
setValue(p, node.get(definition.name()));
127129
} catch (Exception e) {
128130
// Catching Exception instead of RuntimeException, since
129131
// Kotlin-implemented DynamicProperty would throw checked exceptions
130-
logger.warn("Failed to set initial value from CentralDogma for {}", entry.getKey(), e);
132+
logger.warn("Failed to set value from CentralDogma for {}", definition.name(), e);
131133
}
132134
}
133-
});
135+
}
134136
});
135137
}
136138

@@ -163,7 +165,7 @@ public <T> Optional<Property<T>> getProperty(PropertyDefinition<T> definition) {
163165
} catch (Exception e) {
164166
// Catching Exception instead of RuntimeException, since
165167
// Kotlin-implemented DynamicProperty would throw checked exceptions
166-
logger.warn("Failed to set initial value from CentralDogma for {}", definition.name(), e);
168+
logger.warn("Failed to set value from CentralDogma for {}", definition.name(), e);
167169
}
168170
return prop;
169171
});
@@ -247,13 +249,6 @@ public static CentralDogmaPropertySupplier register(CentralDogmaRepository centr
247249

248250
private static void createPropertyFile(CentralDogmaRepository centralDogmaRepository, String fileName,
249251
List<Property<?>> properties) {
250-
// show given properties
251-
logger.info("Creating CentralDogma property file: {} with properties: {}",
252-
fileName,
253-
properties.stream()
254-
.map(p -> String.format("%s=%s", p.definition().name(), p.value()))
255-
.collect(Collectors.joining(", ")));
256-
257252
Revision baseRevision = normalizeRevision(centralDogmaRepository, Revision.HEAD);
258253
boolean fileExists = fileExists(centralDogmaRepository, fileName, baseRevision);
259254
long startedTime = System.currentTimeMillis();

centraldogma/src/test/java/com/linecorp/decaton/centraldogma/CentralDogmaPropertySupplierIntegrationTest.java

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818

1919
import static com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature.WRITE_DOC_START_MARKER;
2020
import static com.linecorp.decaton.processor.runtime.ProcessorProperties.CONFIG_PARTITION_CONCURRENCY;
21-
import static org.junit.jupiter.api.Assertions.*;
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertFalse;
23+
import static org.junit.jupiter.api.Assertions.assertSame;
24+
import static org.junit.jupiter.api.Assertions.assertThrows;
25+
import static org.junit.jupiter.api.Assertions.assertTrue;
26+
import static org.junit.jupiter.api.Assertions.fail;
2227
import static org.mockito.ArgumentMatchers.any;
2328
import static org.mockito.ArgumentMatchers.eq;
2429
import static org.mockito.Mockito.doAnswer;
@@ -36,8 +41,6 @@
3641

3742
import com.fasterxml.jackson.databind.ObjectMapper;
3843
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
39-
import lombok.extern.slf4j.Slf4j;
40-
import org.junit.jupiter.api.Nested;
4144
import org.junit.jupiter.api.Test;
4245
import org.junit.jupiter.api.Timeout;
4346
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -60,7 +63,6 @@
6063
import org.junit.jupiter.params.ParameterizedTest;
6164
import org.junit.jupiter.params.provider.MethodSource;
6265

63-
@Slf4j
6466
public class CentralDogmaPropertySupplierIntegrationTest {
6567
@RegisterExtension
6668
final CentralDogmaExtension extension = new CentralDogmaExtension() {
@@ -210,16 +212,14 @@ void testCDIntegrationYaml() throws Exception {
210212
assertEquals(20, concurrency.value());
211213
assertEquals(java.util.Arrays.asList("123456", "79797979"), ignoreKeys.value());
212214

213-
assertEquals(20,
214-
IntStream.range(0, 10_000)
215-
.mapToObj(i -> CONFIG_PARTITION_CONCURRENCY)
216-
.map(supplier::getProperty)
217-
.reduce((l, r) -> {
218-
assertSame(l.get(), r.get());
219-
return l;
220-
})
221-
.orElseThrow()
222-
.get().value().intValue());
215+
assertEquals(20, IntStream
216+
.range(0, 10_000)
217+
.mapToObj(i -> CONFIG_PARTITION_CONCURRENCY)
218+
.map(supplier::getProperty)
219+
.reduce((l, r) -> {
220+
assertSame(l.get(), r.get());
221+
return l;
222+
}).get().get().value().intValue());
223223
}
224224

225225
@Test
@@ -242,32 +242,26 @@ public void testCDRegisterSuccessJson() {
242242

243243
@Test
244244
@Timeout(10)
245-
public void testCDRegisterSuccessYaml() {
245+
public void testCDRegisterSuccessYaml() throws Exception {
246246
String yamlFile = "/subscription.yaml";
247247
CentralDogma client = extension.client();
248248
client.createProject(PROJECT_NAME).join();
249249
CentralDogmaRepository centralDogmaRepository = client.createRepository(PROJECT_NAME, REPOSITORY_NAME).join();
250250

251251
CentralDogmaPropertySupplier.register(centralDogmaRepository, yamlFile);
252252

253-
String expectedYaml = "decaton.ignore.keys: []\n"
254-
+ "decaton.processing.rate.per.partition: -1\n"
255-
+ "decaton.partition.concurrency: 1\n"
256-
+ "decaton.max.pending.records: 10000\n"
257-
+ "decaton.commit.interval.ms: 1000\n"
258-
+ "decaton.group.rebalance.timeout.ms: 1000\n"
259-
+ "decaton.processing.shutdown.timeout.ms: 0\n"
260-
+ "decaton.logging.mdc.enabled: true\n"
261-
+ "decaton.client.metrics.micrometer.bound: false\n"
262-
+ "decaton.deferred.complete.timeout.ms: -1\n"
263-
+ "decaton.processor.threads.termination.timeout.ms: 9223372036854775807\n"
264-
+ "decaton.per.key.quota.processing.rate: -1\n"
265-
+ "decaton.retry.task.in.legacy.format: false\n"
266-
+ "decaton.legacy.parse.fallback.enabled: false\n";
267-
268253
String actualText = centralDogmaRepository.file(Query.ofText(yamlFile)).get().join().content();
269-
assertEquals(expectedYaml, actualText);
270-
log.info("Content of {}: {}", yamlFile, actualText);
254+
255+
ObjectMapper yaml = new ObjectMapper(new YAMLFactory());
256+
JsonNode actual = yaml.readTree(actualText);
257+
JsonNode expected = defaultProperties();
258+
259+
assertEquals(expected.toString(), actual.toString(),
260+
() -> "\nexpected: " + expected.toPrettyString()
261+
+ "\nactual: " + actual.toPrettyString());
262+
263+
assertFalse(actualText.startsWith("---"), "YAML should not include doc start marker");
264+
assertFalse(actualText.trim().startsWith("{"), "YAML should not be JSON text");
271265
}
272266

273267
@Test
@@ -331,7 +325,7 @@ void testCDRegisterConflictYaml() throws Exception {
331325
"# pushed by user‑B (should win the race)\n"
332326
+ "foo: bar\n";
333327

334-
JsonNode userBPush = Jackson.readTree("{\"foo\":\"bar\"}");
328+
JsonNode userBYamlAsJsonNode = Jackson.readTree("{\"foo\":\"bar\"}");
335329

336330
String defaultYaml = new ObjectMapper(new YAMLFactory().disable(WRITE_DOC_START_MARKER))
337331
.writeValueAsString(defaultProperties());
@@ -344,9 +338,7 @@ void testCDRegisterConflictYaml() throws Exception {
344338
.commit(any(), eq(Change.ofTextUpsert(FILE, defaultYaml)));
345339

346340
ExecutorService svc = Executors.newFixedThreadPool(2);
347-
348341
svc.submit(() -> CentralDogmaPropertySupplier.register(userA, FILE));
349-
350342
svc.submit(() -> {
351343
try {
352344
userAIsRunning.await();
@@ -368,7 +360,7 @@ void testCDRegisterConflictYaml() throws Exception {
368360

369361
JsonNode actual = new ObjectMapper(new YAMLFactory())
370362
.readTree(entry.content());
371-
assertEquals(userBPush, actual);
363+
assertEquals(userBYamlAsJsonNode, actual);
372364
}
373365

374366

centraldogma/src/test/java/com/linecorp/decaton/centraldogma/CentralDogmaPropertySupplierTest.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private CentralDogmaPropertySupplier setup(String fileName) {
114114
return new CentralDogmaPropertySupplier(centralDogmaRepository, fileName);
115115
}
116116

117-
@ParameterizedTest(name = "watcherSetup[{index}] → {0}")
117+
@ParameterizedTest()
118118
@MethodSource("fileParams")
119119
public void testWatcherSetup(String fileName) {
120120
CentralDogmaPropertySupplier supplier = setup(fileName);
@@ -125,7 +125,7 @@ public void testWatcherSetup(String fileName) {
125125
assertTrue(supplier.getProperty(LONG_PROPERTY).isPresent());
126126
}
127127

128-
@ParameterizedTest(name = "watcherSetup[{index}] → {0}")
128+
@ParameterizedTest()
129129
@MethodSource("fileParams")
130130
public void testConvertValue(String fileName) {
131131
CentralDogmaPropertySupplier supplier = setup(fileName);
@@ -143,7 +143,7 @@ public void testConvertValue(String fileName) {
143143
assertEquals(Arrays.asList("foo", "bar"), convertedList);
144144
}
145145

146-
@ParameterizedTest(name = "watcherSetup[{index}] → {0}")
146+
@ParameterizedTest()
147147
@MethodSource("fileParams")
148148
public void testSetValue(String fileName) {
149149
CentralDogmaPropertySupplier supplier = setup(fileName);
@@ -155,7 +155,18 @@ public void testSetValue(String fileName) {
155155
verify(prop).checkingSet(10L);
156156
}
157157

158-
@ParameterizedTest(name = "watcherSetup[{index}] → {0}")
158+
@ParameterizedTest()
159+
@MethodSource("fileParams")
160+
public void testSetNullValue(String fileName) {
161+
CentralDogmaPropertySupplier supplier = setup(fileName);
162+
JsonNodeFactory factory = objectMapper.getNodeFactory();
163+
164+
DynamicProperty<Long> prop = spy(new DynamicProperty<>(LONG_PROPERTY));
165+
supplier.setValue(prop, factory.nullNode());
166+
verify(prop).checkingSet(LONG_PROPERTY.defaultValue());
167+
}
168+
169+
@ParameterizedTest()
159170
@MethodSource("fileParams")
160171
public void testGetPropertyAbsentName(String fileName) {
161172
CentralDogmaPropertySupplier supplier = setup(fileName);
@@ -166,16 +177,6 @@ public void testGetPropertyAbsentName(String fileName) {
166177
assertFalse(supplier.getProperty(missingProperty).isPresent());
167178
}
168179

169-
// @Test
170-
// public void testSetNullValue() {
171-
// JsonNodeFactory factory = objectMapper.getNodeFactory();
172-
//
173-
// DynamicProperty<Long> prop = spy(new DynamicProperty<>(LONG_PROPERTY));
174-
// supplier.setValue(prop, factory.nullNode());
175-
// verify(prop).checkingSet(LONG_PROPERTY.defaultValue());
176-
// }
177-
178-
179180
private Change<?> expectedChange(String fileName, JsonNode node) throws Exception {
180181
if (fileName.endsWith(".yaml") || fileName.endsWith(".yml")) {
181182
return Change.ofTextUpsert(fileName, YAML_MAPPER.writeValueAsString(node));
@@ -184,7 +185,7 @@ private Change<?> expectedChange(String fileName, JsonNode node) throws Exceptio
184185
}
185186
}
186187

187-
@ParameterizedTest(name = "watcherSetup[{index}] → {0}")
188+
@ParameterizedTest()
188189
@MethodSource("fileParams")
189190
public void testRegisterWithDefaultSettings(String fileName) throws Exception {
190191
setup(fileName);
@@ -209,7 +210,7 @@ public void testRegisterWithDefaultSettings(String fileName) throws Exception {
209210
);
210211
}
211212

212-
@ParameterizedTest(name = "watcherSetup[{index}] → {0}")
213+
@ParameterizedTest()
213214
@MethodSource("fileParams")
214215
public void testRegisterWithCustomizedSettings(String fileName) throws Exception {
215216
setup(fileName);

0 commit comments

Comments
 (0)