From 69bf853be5daa26bfa3493f9fa1ed7d583a6db32 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Wed, 21 Feb 2024 10:35:58 +0100 Subject: [PATCH] Fixes #9341 - jetty-jmh 10.013 fails due to "java.lang.AssertionError: No trie for TernaryTrie" Fixed by using an enum and expression switch to avoid using string constants that may become obsolete. Signed-off-by: Simone Bordet --- .../org/eclipse/jetty/util/TrieBenchmark.java | 50 ++++++++----------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/tests/jetty-jmh/src/main/java/org/eclipse/jetty/util/TrieBenchmark.java b/tests/jetty-jmh/src/main/java/org/eclipse/jetty/util/TrieBenchmark.java index 30456d5ed031..873e9fbfbbda 100644 --- a/tests/jetty-jmh/src/main/java/org/eclipse/jetty/util/TrieBenchmark.java +++ b/tests/jetty-jmh/src/main/java/org/eclipse/jetty/util/TrieBenchmark.java @@ -16,7 +16,6 @@ import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -36,44 +35,35 @@ @State(Scope.Benchmark) public class TrieBenchmark { - @Param({ - "ArrayTrie", - "TernaryTrie", - "ArrayTernaryTrie", - "TreeTrie", - "HashTrie", - }) - public static String TRIE_TYPE; - - private AbstractTrie trie; - private static final String LONG_HIT = "This-is-a-Moderately-Long-Key-that-will-hit"; private static final String LONG_MISS = "This-is-a-Moderately-Long-Key-that-will-miss"; + public enum TrieType + { + ARRAY_TRIE, + ARRAY_TERNARY_TRIE, + TREE_TRIE, + HASH_TRIE, + } + + @Param + public TrieType trieType; + + private AbstractTrie trie; + @Setup - public void setUp() throws Exception + public void setUp() { boolean caseSensitive = false; - Set alphabet = new HashSet<>(); int capacity = 4096; - switch (TRIE_TYPE) + trie = switch (trieType) { - case "ArrayTrie": - trie = new ArrayTrie<>(caseSensitive, capacity); - break; - case "ArrayTernaryTrie": - trie = new ArrayTernaryTrie<>(caseSensitive, capacity); - break; - case "TreeTrie": - trie = new TreeTrie(); - break; - case "HashTrie": - trie = new HashTrie(caseSensitive); - break; - default: - throw new AssertionError("No trie for " + TRIE_TYPE); - } + case ARRAY_TRIE -> new ArrayTrie<>(caseSensitive, capacity); + case ARRAY_TERNARY_TRIE -> new ArrayTernaryTrie<>(caseSensitive, capacity); + case TREE_TRIE -> new TreeTrie(); + case HASH_TRIE -> new HashTrie(caseSensitive); + }; for (String k : HttpParser.CACHE.keySet()) if (!trie.put(k, HttpParser.CACHE.get(k).toString()))