Skip to content

Commit 06b7ff2

Browse files
authored
OAK-11774 : removed usage of guava splitter (#2380)
* OAK-11774 : removed usage of guava splitter * OAK-11774 : improved test coverage * OAK-11774 : mimic exact behaviour of Guava's Splitter via Stream's code using -1 limit in split method
1 parent 69ee5b5 commit 06b7ff2

File tree

25 files changed

+509
-73
lines changed

25 files changed

+509
-73
lines changed

oak-benchmarks-lucene/src/main/java/org/apache/jackrabbit/oak/scalability/suites/ScalabilityNodeRelationshipSuite.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
package org.apache.jackrabbit.oak.scalability.suites;
2020

2121
import java.util.ArrayList;
22+
import java.util.Arrays;
2223
import java.util.Calendar;
2324
import java.util.HashMap;
2425
import java.util.List;
2526
import java.util.Map;
2627
import java.util.Random;
2728
import java.util.UUID;
29+
import java.util.stream.Collectors;
2830

2931
import javax.jcr.Node;
3032
import javax.jcr.NodeIterator;
@@ -49,8 +51,6 @@
4951
import org.slf4j.Logger;
5052
import org.slf4j.LoggerFactory;
5153

52-
import org.apache.jackrabbit.guava.common.base.Splitter;
53-
5454
/**
5555
* The suite test will incrementally increase the load and execute searches.
5656
* Each test run thus adds nodes and executes different benchmarks. This way we measure time
@@ -99,8 +99,10 @@ public class ScalabilityNodeRelationshipSuite extends ScalabilityNodeSuite {
9999
public static final String OBJECT_ID = "objectId";
100100
public static final String TARGET = "target";
101101

102-
protected static final List<String> NODE_LEVELS = Splitter.on(",").trimResults()
103-
.omitEmptyStrings().splitToList(System.getProperty("nodeLevels", "10,5,2,1"));
102+
protected static final List<String> NODE_LEVELS = Arrays.stream(System.getProperty("nodeLevels", "10,5,2,1").split(","))
103+
.map(String::trim)
104+
.filter(s -> !s.isEmpty())
105+
.collect(Collectors.toList());
104106

105107
protected static final List<String> NODE_LEVELS_DEFAULT = List.of("10","5","2","1");
106108

oak-benchmarks-lucene/src/main/java/org/apache/jackrabbit/oak/scalability/suites/ScalabilityNodeSuite.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919
package org.apache.jackrabbit.oak.scalability.suites;
2020

2121
import java.util.ArrayList;
22+
import java.util.Arrays;
2223
import java.util.Calendar;
2324
import java.util.HashMap;
2425
import java.util.List;
2526
import java.util.Map;
2627
import java.util.Random;
2728
import java.util.TimeZone;
2829
import java.util.concurrent.TimeUnit;
30+
import java.util.stream.Collectors;
2931

3032
import javax.jcr.Node;
3133
import javax.jcr.PropertyType;
@@ -34,8 +36,6 @@
3436
import javax.jcr.Session;
3537

3638
import org.apache.commons.lang3.StringUtils;
37-
import org.apache.jackrabbit.guava.common.base.Splitter;
38-
3939
import org.apache.commons.math3.stat.descriptive.SynchronizedDescriptiveStatistics;
4040
import org.apache.jackrabbit.commons.JcrUtils;
4141
import org.apache.jackrabbit.oak.Oak;
@@ -108,8 +108,10 @@ public class ScalabilityNodeSuite extends ScalabilityAbstractSuite {
108108
/**
109109
* Controls the number of nodes at each level
110110
*/
111-
protected static final List<String> NODE_LEVELS = Splitter.on(",").trimResults()
112-
.omitEmptyStrings().splitToList(System.getProperty("nodeLevels", "10,5,2"));
111+
protected static final List<String> NODE_LEVELS = Arrays.stream(System.getProperty("nodeLevels", "10,5,2").split(","))
112+
.map(String::trim)
113+
.filter(s -> !s.isEmpty())
114+
.collect(Collectors.toList());
113115

114116
/**
115117
* Controls the number of concurrent tester threads
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.jackrabbit.oak.scalability.suites;
21+
22+
import org.junit.After;
23+
import org.junit.Before;
24+
import org.junit.Test;
25+
26+
import java.lang.reflect.Field;
27+
import java.util.Arrays;
28+
import java.util.List;
29+
import java.util.stream.Collectors;
30+
31+
import static org.junit.Assert.assertEquals;
32+
33+
/**
34+
* Test suite for ScalabilityNodeRelationshipSuite
35+
*/
36+
public class ScalabilityNodeRelationshipSuiteTest {
37+
38+
private String originalNodeLevelsProperty;
39+
40+
@Before
41+
public void saveOriginalProperty() {
42+
originalNodeLevelsProperty = System.getProperty("nodeLevels");
43+
}
44+
45+
@After
46+
public void restoreOriginalProperty() {
47+
if (originalNodeLevelsProperty == null) {
48+
System.clearProperty("nodeLevels");
49+
} else {
50+
System.setProperty("nodeLevels", originalNodeLevelsProperty);
51+
}
52+
}
53+
54+
@Test
55+
public void testDefaultNodeLevels() throws Exception {
56+
System.clearProperty("nodeLevels");
57+
58+
// Create a new instance to initialize static fields
59+
new TestScalabilityNodeRelationshipSuite();
60+
61+
Field nodeLevelsField = ScalabilityNodeRelationshipSuite.class.getDeclaredField("NODE_LEVELS");
62+
nodeLevelsField.setAccessible(true);
63+
List<String> nodeLevels = (List<String>) nodeLevelsField.get(null);
64+
65+
// Clear and populate the list with new values
66+
nodeLevels.clear();
67+
nodeLevels.addAll(getNodeLevels(System.getProperty("nodeLevels", "10,5,2,1")));
68+
69+
assertEquals(4, nodeLevels.size());
70+
assertEquals("10", nodeLevels.get(0));
71+
assertEquals("5", nodeLevels.get(1));
72+
assertEquals("2", nodeLevels.get(2));
73+
assertEquals("1", nodeLevels.get(3));
74+
}
75+
76+
@Test
77+
public void testCustomNodeLevels() throws Exception {
78+
System.setProperty("nodeLevels", "20,10,5,2");
79+
80+
// Create a new instance to initialize static fields
81+
new TestScalabilityNodeRelationshipSuite();
82+
83+
Field nodeLevelsField = ScalabilityNodeRelationshipSuite.class.getDeclaredField("NODE_LEVELS");
84+
nodeLevelsField.setAccessible(true);
85+
List<String> nodeLevels = (List<String>) nodeLevelsField.get(null);
86+
87+
// Clear and populate the list with new values
88+
nodeLevels.clear();
89+
nodeLevels.addAll(getNodeLevels(System.getProperty("nodeLevels", "10,5,2,1")));
90+
91+
assertEquals(4, nodeLevels.size());
92+
assertEquals("20", nodeLevels.get(0));
93+
assertEquals("10", nodeLevels.get(1));
94+
assertEquals("5", nodeLevels.get(2));
95+
assertEquals("2", nodeLevels.get(3));
96+
}
97+
98+
@Test
99+
public void testWhitespaceTrimmingInNodeLevels() throws Exception {
100+
System.setProperty("nodeLevels", " 15 , 8 , 4 , 2 ");
101+
102+
// Create a new instance to initialize static fields
103+
new TestScalabilityNodeRelationshipSuite();
104+
105+
Field nodeLevelsField = ScalabilityNodeRelationshipSuite.class.getDeclaredField("NODE_LEVELS");
106+
nodeLevelsField.setAccessible(true);
107+
List<String> nodeLevels = (List<String>) nodeLevelsField.get(null);
108+
109+
// Clear and populate the list with new values
110+
nodeLevels.clear();
111+
nodeLevels.addAll(getNodeLevels(System.getProperty("nodeLevels", "10,5,2,1")));
112+
113+
assertEquals(4, nodeLevels.size());
114+
assertEquals("15", nodeLevels.get(0));
115+
assertEquals("8", nodeLevels.get(1));
116+
assertEquals("4", nodeLevels.get(2));
117+
assertEquals("2", nodeLevels.get(3));
118+
}
119+
120+
@Test
121+
public void testEmptyValuesFiltering() throws Exception {
122+
System.setProperty("nodeLevels", "25,,10,,3");
123+
124+
// Create a new instance to initialize static fields
125+
new TestScalabilityNodeRelationshipSuite();
126+
127+
Field nodeLevelsField = ScalabilityNodeRelationshipSuite.class.getDeclaredField("NODE_LEVELS");
128+
nodeLevelsField.setAccessible(true);
129+
List<String> nodeLevels = (List<String>) nodeLevelsField.get(null);
130+
131+
// Clear and populate the list with new values
132+
nodeLevels.clear();
133+
nodeLevels.addAll(getNodeLevels(System.getProperty("nodeLevels", "10,5,2,1")));
134+
135+
assertEquals(3, nodeLevels.size());
136+
assertEquals("25", nodeLevels.get(0));
137+
assertEquals("10", nodeLevels.get(1));
138+
assertEquals("3", nodeLevels.get(2));
139+
}
140+
141+
@Test
142+
public void testDifferentNumberOfLevels() throws Exception {
143+
System.setProperty("nodeLevels", "50,25,10");
144+
145+
// Create a new instance to initialize static fields
146+
new TestScalabilityNodeRelationshipSuite();
147+
148+
Field nodeLevelsField = ScalabilityNodeRelationshipSuite.class.getDeclaredField("NODE_LEVELS");
149+
nodeLevelsField.setAccessible(true);
150+
List<String> nodeLevels = (List<String>) nodeLevelsField.get(null);
151+
152+
// Clear and populate the list with new values
153+
nodeLevels.clear();
154+
nodeLevels.addAll(getNodeLevels(System.getProperty("nodeLevels", "10,5,2,1")));
155+
156+
assertEquals(3, nodeLevels.size());
157+
assertEquals("50", nodeLevels.get(0));
158+
assertEquals("25", nodeLevels.get(1));
159+
assertEquals("10", nodeLevels.get(2));
160+
}
161+
162+
private List<String> getNodeLevels(String value) {
163+
return Arrays.stream(System.getProperty("nodeLevels", "10,5,2,1").split(","))
164+
.map(String::trim)
165+
.filter(s -> !s.isEmpty())
166+
.collect(Collectors.toList());
167+
}
168+
169+
// Test subclass to access protected members
170+
private static class TestScalabilityNodeRelationshipSuite extends ScalabilityNodeRelationshipSuite {
171+
public TestScalabilityNodeRelationshipSuite() {
172+
super(false);
173+
}
174+
}
175+
}

oak-benchmarks/src/main/java/org/apache/jackrabbit/oak/scalability/ScalabilityRunner.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
import java.util.List;
3030
import java.util.Map;
3131
import java.util.Set;
32+
import java.util.stream.Collectors;
3233

33-
import org.apache.jackrabbit.guava.common.base.Splitter;
3434
import joptsimple.OptionParser;
3535
import joptsimple.OptionSet;
3636
import org.apache.commons.io.FileUtils;
@@ -140,9 +140,11 @@ public static void main(String[] args) throws Exception {
140140
Map<String, List<String>> argmap = new HashMap<>();
141141
// Split the args to get suites and benchmarks (i.e. suite:benchmark1,benchmark2)
142142
for(String arg : argset) {
143-
List<String> tokens = Splitter.on(":").limit(2).splitToList(arg);
143+
List<String> tokens = Arrays.stream(arg.split(":", 2)).collect(Collectors.toList());
144144
if (tokens.size() > 1) {
145-
argmap.put(tokens.get(0), Splitter.on(",").trimResults().splitToList(tokens.get(1)));
145+
argmap.put(tokens.get(0), Arrays.stream(tokens.get(1).split(","))
146+
.map(String::trim)
147+
.collect(Collectors.toList()));
146148
} else {
147149
argmap.put(tokens.get(0), null);
148150
}

oak-benchmarks/src/main/java/org/apache/jackrabbit/oak/scalability/suites/ScalabilityAbstractSuite.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.io.PrintStream;
2222
import java.util.ArrayList;
23+
import java.util.Arrays;
2324
import java.util.LinkedHashMap;
2425
import java.util.LinkedList;
2526
import java.util.List;
@@ -29,15 +30,14 @@
2930
import java.util.concurrent.ConcurrentHashMap;
3031
import java.util.concurrent.TimeUnit;
3132
import java.util.concurrent.atomic.AtomicLong;
33+
import java.util.stream.Collectors;
3234

3335
import javax.jcr.Credentials;
3436
import javax.jcr.Repository;
3537
import javax.jcr.RepositoryException;
3638
import javax.jcr.Session;
3739
import javax.jcr.SimpleCredentials;
3840

39-
import org.apache.jackrabbit.guava.common.base.Splitter;
40-
4141
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
4242
import org.apache.commons.math3.stat.descriptive.SynchronizedDescriptiveStatistics;
4343
import org.apache.jackrabbit.oak.benchmark.CSVResultGenerator;
@@ -102,8 +102,10 @@ public abstract class ScalabilityAbstractSuite implements ScalabilitySuite, CSVR
102102
/**
103103
* Controls the incremental load for each iteration
104104
*/
105-
protected static final List<String> INCREMENTS = Splitter.on(",").trimResults()
106-
.omitEmptyStrings().splitToList(System.getProperty("increments", "1,2,5"));
105+
protected static final List<String> INCREMENTS = Arrays.stream(System.getProperty("increments", "1,2,5").split(","))
106+
.map(String::trim)
107+
.filter(s -> !s.isEmpty())
108+
.collect(Collectors.toList());
107109

108110
protected static final Credentials CREDENTIALS = new SimpleCredentials("admin", "admin"
109111
.toCharArray());

0 commit comments

Comments
 (0)