PakhomovAlexander commented on code in PR #1929:
URL: https://github.com/apache/ignite-3/pull/1929#discussion_r1170024228


##########
modules/runner/src/test/java/org/apache/ignite/internal/configuration/storage/LocalFileConfigurationStorageTest.java:
##########
@@ -17,75 +17,401 @@
 
 package org.apache.ignite.internal.configuration.storage;
 
-import static 
org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.aMapWithSize;
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.emptyString;
+import static org.hamcrest.Matchers.equalToCompressingWhiteSpace;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.hasValue;
 import static org.hamcrest.Matchers.is;
 
 import java.io.IOException;
+import java.io.Serializable;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import org.apache.ignite.configuration.annotation.Config;
+import org.apache.ignite.configuration.annotation.ConfigurationRoot;
+import org.apache.ignite.configuration.annotation.NamedConfigValue;
+import org.apache.ignite.configuration.annotation.Value;
+import org.apache.ignite.internal.configuration.TestConfigurationChanger;
+import org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator;
 import org.apache.ignite.internal.testframework.WorkDirectory;
 import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
-import org.junit.jupiter.api.Disabled;
+import org.hamcrest.Matchers;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 
-/**
- * Tests for the {@link LocalFileConfigurationStorage}.
- */
+/** Test for local file configurations storage. */
 @ExtendWith(WorkDirectoryExtension.class)
-@Disabled("https://issues.apache.org/jira/browse/IGNITE-19152";)
-public class LocalFileConfigurationStorageTest extends 
ConfigurationStorageTest {
+public class LocalFileConfigurationStorageTest {
 
     private static final String CONFIG_NAME = "ignite-config.conf";
 
+    private static ConfigurationAsmGenerator cgen;
+
     @WorkDirectory
     private Path tmpDir;
 
-    @Override
-    public ConfigurationStorage getStorage() {
-        return new LocalFileConfigurationStorage(getConfigFile());
+    /** Test configuration storage. */
+    private LocalFileConfigurationStorage storage;
+
+    /** Test configuration changer. */
+    private TestConfigurationChanger changer;
+
+    /** Instantiates {@link #cgen}. */
+    @BeforeAll
+    public static void beforeAll() {
+        cgen = new ConfigurationAsmGenerator();
+    }
+
+    /** Nullifies {@link #cgen} to prevent memory leak from having runtime 
ClassLoader accessible from GC root. */
+    @AfterAll
+    public static void afterAll() {
+        cgen = null;
+    }
+
+    private Path getConfigFile() {
+        return tmpDir.resolve(CONFIG_NAME);
+    }
+
+    @BeforeEach
+    void before() {
+        storage = new LocalFileConfigurationStorage(getConfigFile(), 
List.of(TopConfiguration.KEY));
+
+        changer = new TestConfigurationChanger(
+                cgen,
+                List.of(TopConfiguration.KEY),
+                Set.of(),
+                storage,
+                List.of(),
+                List.of()
+        );
+
+        changer.start();
+    }
+
+    @AfterEach
+    void after() {
+        changer.stop();
     }
 
     @Test
-    void testHocon() throws IOException {
-        // All of this is needed because write expects serializable values and 
only concrete classes are serializable
-        HashMap<String, ArrayList<String>> map = new HashMap<>(Map.of("list", 
new ArrayList<>(List.of("val1", "val2"))));
-        var data = Map.of("foo1", "bar1", "foo2", "bar2", "map", map);
-
-        assertThat(storage.write(data, 0), willBe(true));
-
-        String contents = Files.readString(getConfigFile());
-
-        // \n instead of System.lineSeparator because Config library writes \n 
only
-        assertThat(contents, is("foo1=bar1\n"
-                + "foo2=bar2\n"
-                + "map {\n"
-                + "    list=[\n"
-                + "        val1,\n"
-                + "        val2\n"
-                + "    ]\n"
-                + "}\n"));
+    @DisplayName("Default values are not added enriched on read when the 
config file is empty")
+    void empty() throws IOException {
+        // Given
+        assertThat(configFileContent(), emptyString());
+
+        // When
+        var storageValues = readAllLatest();
+
+        // Then storage data only contains top level defaults
+        assertThat(storageValues.entrySet(), hasSize(1));
     }
 
     @Test
-    void testMergeHocon() throws IOException {
-        var data = Map.of("foo1", "bar");
-        assertThat(storage.write(data, 0), willBe(true));
+    @DisplayName("Named list entities can be added")
+    void add() throws Exception {
+        // Given
+        assertThat(configFileContent(), emptyString());
+        // And
+        var topConfiguration = (TopConfiguration) 
cgen.instantiateCfg(TopConfiguration.KEY, changer);
+        topConfiguration.namedList().change(b -> b.create("name1", x -> {
+            x.changeStrVal("strVal1");
+            x.changeIntVal(-1);
+        })).get();
+
+        // When
+        var storageValues = readAllLatest();
 
-        var append = Map.of("foo1", "baz", "foo2", "bar");
-        assertThat(storage.write(append, 1), willBe(true));
+        // Then
+        assertThat(storageValues, allOf(aMapWithSize(6), hasValue(-1)));
+        assertThat(storageValues, allOf(aMapWithSize(6), hasValue("strVal1")));
+        // And
+        assertThat(configFileContent(), equalToCompressingWhiteSpace(
+                "top {\n"
+                        + "    namedList=[\n"
+                        + "        {\n"
+                        + "            intVal=-1\n"
+                        + "            name=name1\n"
+                        + "            strVal=strVal1\n"
+                        + "        }\n"

Review Comment:
   https://issues.apache.org/jira/browse/IGNITE-19303



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to