Skip to content

Commit

Permalink
Load large yaml files (#1039)
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry authored Sep 28, 2024
1 parent ec6b09a commit b51be48
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class YAML {

private YAML() {}

private static final Load snakeYaml = new Load(LoadSettings.builder().build());
private static final Load snakeYaml = new Load(LoadSettings.builder().setCodePointLimit(Integer.MAX_VALUE).build());
public static final ObjectMapper jackson = new ObjectMapper();

public static <T> T load(Path file, Class<T> clazz) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.onthegomap.planetiler.util;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;

class YamlTest {
@Test
void testLoadYamlRaw() {
assertEquals(Map.of("a", 1), YAML.load("""
a: 1
""", Object.class));
}

@Test
void testLoadYamlToClass() {
record Result(int a) {}
assertEquals(new Result(1), YAML.load("""
a: 1
""", Result.class));
}

@Test
void testLoadLargeYamlList() {
StringBuilder builder = new StringBuilder();
List<Integer> expected = new ArrayList<>();
for (int i = 0; i < 500_000; i++) {
builder.append("\n- ").append(i);
expected.add(i);
}
assertEquals(expected, YAML.load(builder.toString(), List.class));
}

@Test
void testLoadLargeYamlMap() {
StringBuilder builder = new StringBuilder();
Map<String, Integer> expected = new HashMap<>();
for (int i = 0; i < 500_000; i++) {
builder.append('\n').append(i).append(": ").append(i);
expected.put(Integer.toString(i), i);
}
assertEquals(expected, YAML.load(builder.toString(), Map.class));
}
}

0 comments on commit b51be48

Please sign in to comment.