Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hailin0 committed Oct 23, 2024
1 parent c966169 commit 14942b6
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 12 deletions.
18 changes: 18 additions & 0 deletions seatunnel-config/seatunnel-config-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,29 @@
<exclude>com/typesafe/config/ConfigParseOptions.class</exclude>
<exclude>com/typesafe/config/ConfigMergeable.class</exclude>
<exclude>com/typesafe/config/impl/ConfigParser.class</exclude>
<exclude>com/typesafe/config/impl/ConfigParser$1.class</exclude>
<exclude>com/typesafe/config/impl/ConfigParser$ParseContext.class</exclude>
<exclude>com/typesafe/config/impl/ConfigNodePath.class</exclude>
<exclude>com/typesafe/config/impl/PathParser.class</exclude>
<exclude>com/typesafe/config/impl/PathParser$Element.class</exclude>
<exclude>com/typesafe/config/impl/Path.class</exclude>
<exclude>com/typesafe/config/impl/SimpleConfigObject.class</exclude>
<exclude>com/typesafe/config/impl/SimpleConfigObject$1.class</exclude>
<exclude>com/typesafe/config/impl/SimpleConfigObject$RenderComparator.class</exclude>
<exclude>com/typesafe/config/impl/SimpleConfigObject$ResolveModifier.class</exclude>
<exclude>com/typesafe/config/impl/PropertiesParser.class</exclude>
<exclude>com/typesafe/config/impl/PropertiesParser$1.class</exclude>
<exclude>com/typesafe/config/impl/ConfigImpl.class</exclude>
<exclude>com/typesafe/config/impl/ConfigImpl$1.class</exclude>
<exclude>com/typesafe/config/impl/ConfigImpl$ClasspathNameSource.class</exclude>
<exclude>com/typesafe/config/impl/ConfigImpl$ClasspathNameSourceWithClass.class</exclude>
<exclude>com/typesafe/config/impl/ConfigImpl$DebugHolder.class</exclude>
<exclude>com/typesafe/config/impl/ConfigImpl$DefaultIncluderHolder.class</exclude>
<exclude>com/typesafe/config/impl/ConfigImpl$EnvVariablesHolder.class</exclude>
<exclude>com/typesafe/config/impl/ConfigImpl$FileNameSource.class</exclude>
<exclude>com/typesafe/config/impl/ConfigImpl$LoaderCache.class</exclude>
<exclude>com/typesafe/config/impl/ConfigImpl$LoaderCacheHolder.class</exclude>
<exclude>com/typesafe/config/impl/ConfigImpl$SystemPropertiesHolder.class</exclude>
</excludes>
</filter>
</filters>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
Expand All @@ -41,7 +41,7 @@ private static class LoaderCache {
LoaderCache() {
this.currentSystemProperties = null;
this.currentLoader = new WeakReference<ClassLoader>(null);
this.cache = new HashMap<String, Config>();
this.cache = new LinkedHashMap<String, Config>();
}

// for now, caching as long as the loader remains the same,
Expand Down Expand Up @@ -232,7 +232,7 @@ static AbstractConfigValue fromAnyRef(Object object, ConfigOrigin origin, FromMa

if (mapMode == FromMapMode.KEYS_ARE_KEYS) {
Map<String, AbstractConfigValue> values =
new HashMap<String, AbstractConfigValue>();
new LinkedHashMap<String, AbstractConfigValue>();
for (Map.Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) {
Object key = entry.getKey();
if (!(key instanceof String))
Expand Down Expand Up @@ -373,7 +373,7 @@ private static class DebugHolder {
private static String SUBSTITUTIONS = "substitutions";

private static Map<String, Boolean> loadDiagnostics() {
Map<String, Boolean> result = new HashMap<String, Boolean>();
Map<String, Boolean> result = new LinkedHashMap<String, Boolean>();
result.put(LOADS, false);
result.put(SUBSTITUTIONS, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -277,7 +278,7 @@ protected SimpleConfigObject mergedWithObject(AbstractConfigObject abstractFallb
boolean changed = false;
boolean allResolved = true;
Map<String, AbstractConfigValue> merged = new LinkedHashMap<>();
Set<String> allKeys = new HashSet<>();
Set<String> allKeys = new LinkedHashSet<>();
allKeys.addAll(this.keySet());
allKeys.addAll(fallback.keySet());

Expand Down Expand Up @@ -386,8 +387,7 @@ ResolveResult<? extends AbstractConfigObject> resolveSubstitutions(
ResolveSource sourceWithParent = source.pushParent(this);

try {
SimpleConfigObject.ResolveModifier modifier =
new SimpleConfigObject.ResolveModifier(context, sourceWithParent);
ResolveModifier modifier = new ResolveModifier(context, sourceWithParent);
AbstractConfigValue value = this.modifyMayThrow(modifier);
return ResolveResult.make(modifier.context, value).asObjectResult();
} catch (NotPossibleToResolve | RuntimeException var6) {
Expand Down Expand Up @@ -562,7 +562,7 @@ public boolean containsValue(Object v) {
}

public Set<Entry<String, ConfigValue>> entrySet() {
HashSet<Entry<String, ConfigValue>> entries = new HashSet<>();
HashSet<Entry<String, ConfigValue>> entries = new LinkedHashSet<>();

for (Entry<String, AbstractConfigValue> stringAbstractConfigValueEntry :
this.value.entrySet()) {
Expand All @@ -584,7 +584,7 @@ public int size() {
}

public Collection<ConfigValue> values() {
return new HashSet<>(this.value.values());
return new ArrayList<>(this.value.values());
}

static SimpleConfigObject empty() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.seatunnel.config;

import org.apache.seatunnel.shade.com.typesafe.config.Config;
import org.apache.seatunnel.shade.com.typesafe.config.ConfigFactory;
import org.apache.seatunnel.shade.com.typesafe.config.ConfigRenderOptions;

import org.apache.seatunnel.config.utils.FileUtils;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.net.URISyntaxException;

public class ConfigTest {

@Test
public void testConfigKeyOrder() throws URISyntaxException {
String expected =
"{\"env\":{\"job.mode\":\"BATCH\"},\"source\":[{\"row.num\":100,\"schema\":{\"fields\":{\"name\":\"string\",\"age\":\"int\"}},\"plugin_name\":\"FakeSource\"}],\"sink\":[{\"plugin_name\":\"Console\"}]}\n";

Config config =
ConfigFactory.parseFile(
FileUtils.getFileFromResources("/seatunnel/serialize.conf"));
Assertions.assertEquals(expected, config.root().render(ConfigRenderOptions.concise()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -123,7 +123,7 @@ public static Config of(
public static Map<String, Object> configDesensitization(Map<String, Object> configMap) {
return configMap.entrySet().stream()
.collect(
HashMap::new,
LinkedHashMap::new,
(m, p) -> {
String key = p.getKey();
Object value = p.getValue();
Expand Down Expand Up @@ -154,7 +154,7 @@ public static Map<String, Object> configDesensitization(Map<String, Object> conf
}
}
},
HashMap::putAll);
LinkedHashMap::putAll);
}

public static Config of(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.apache.seatunnel.core.starter.utils;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class ConfigBuilderTest {

@Test
public void testConfigDesensitizationSort() {
Map<String, Object> config = new LinkedHashMap<>();
config.put("a", "1");
config.put("b", "1");
config.put("c", "1");
config.put("d", "1");
config.put("e", "1");
config.put("f", "1");

Map<String, Object> desensitizationConfig = ConfigBuilder.configDesensitization(config);
List<String> keys = new ArrayList<>(desensitizationConfig.keySet());
Assertions.assertIterableEquals(Arrays.asList("a", "b", "c", "d", "e", "f"), keys);
}
}

0 comments on commit 14942b6

Please sign in to comment.