Skip to content

Commit eed88b6

Browse files
authored
Autoformat :qa:os and :benchmarks (#52820)
Add `:qa:os` and `:benchmarks` to the list of automatically formatted projects, and apply some manual fix-ups to polish it up. In particular, I noticed that `Files.write(...)` when passed a list will automaticaly apply a UTF-8 encoding and write a newline after each line, making it easier to use than FileUtils.append. It's even available from 1.8. Also, in the Allocators class, a number of methods declared thrown exceptions that IntelliJ reported were never thrown, and as far as I could see this is true, so I removed the exceptions.
1 parent 8ca45e1 commit eed88b6

25 files changed

+424
-467
lines changed

benchmarks/src/main/java/org/elasticsearch/benchmark/fs/AvailableIndexFoldersBenchmark.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ public class AvailableIndexFoldersBenchmark {
5555
@Setup
5656
public void setup() throws IOException {
5757
Path path = Files.createTempDirectory("test");
58-
String[] paths = new String[] {path.toString()};
58+
String[] paths = new String[] { path.toString() };
5959
nodePath = new NodeEnvironment.NodePath(path);
6060

6161
LogConfigurator.setNodeName("test");
6262
Settings settings = Settings.builder()
6363
.put(Environment.PATH_HOME_SETTING.getKey(), path)
64-
.putList(Environment.PATH_DATA_SETTING.getKey(), paths).build();
64+
.putList(Environment.PATH_DATA_SETTING.getKey(), paths)
65+
.build();
6566
nodeEnv = new NodeEnvironment(settings, new Environment(settings, null));
6667

6768
Files.createDirectories(nodePath.indicesPath);
@@ -80,7 +81,6 @@ public void setup() throws IOException {
8081
}
8182
}
8283

83-
8484
@Benchmark
8585
public Set<String> availableIndexFolderNaive() throws IOException {
8686
return nodeEnv.availableIndexFoldersForPath(nodePath);

benchmarks/src/main/java/org/elasticsearch/benchmark/indices/breaker/MemoryStatsBenchmark.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
@BenchmarkMode(Mode.AverageTime)
4242
@OutputTimeUnit(TimeUnit.MICROSECONDS)
4343
@State(Scope.Benchmark)
44-
@SuppressWarnings("unused") //invoked by benchmarking framework
44+
@SuppressWarnings("unused") // invoked by benchmarking framework
4545
public class MemoryStatsBenchmark {
4646
private static final MemoryMXBean MEMORY_MX_BEAN = ManagementFactory.getMemoryMXBean();
4747

48-
@Param({"0", "16", "256", "4096"})
48+
@Param({ "0", "16", "256", "4096" })
4949
private int tokens;
5050

5151
@Benchmark
@@ -102,4 +102,3 @@ public long getMemoryStats_64() {
102102
return MEMORY_MX_BEAN.getHeapMemoryUsage().getUsed();
103103
}
104104
}
105-

benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/AllocationBenchmark.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
@BenchmarkMode(Mode.AverageTime)
5050
@OutputTimeUnit(TimeUnit.MILLISECONDS)
5151
@State(Scope.Benchmark)
52-
@SuppressWarnings("unused") //invoked by benchmarking framework
52+
@SuppressWarnings("unused") // invoked by benchmarking framework
5353
public class AllocationBenchmark {
5454
// Do NOT make any field final (even if it is not annotated with @Param)! See also
5555
// http://hg.openjdk.java.net/code-tools/jmh/file/tip/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_10_ConstantFold.java
@@ -106,8 +106,7 @@ public class AllocationBenchmark {
106106
" 10| 10| 2| 50",
107107
" 100| 1| 2| 50",
108108
" 100| 3| 2| 50",
109-
" 100| 10| 2| 50"
110-
})
109+
" 100| 10| 2| 50" })
111110
public String indicesShardsReplicasNodes = "10|1|0|1";
112111

113112
public int numTags = 2;
@@ -124,13 +123,14 @@ public void setUp() throws Exception {
124123
int numReplicas = toInt(params[2]);
125124
int numNodes = toInt(params[3]);
126125

127-
strategy = Allocators.createAllocationService(Settings.builder()
128-
.put("cluster.routing.allocation.awareness.attributes", "tag")
129-
.build());
126+
strategy = Allocators.createAllocationService(
127+
Settings.builder().put("cluster.routing.allocation.awareness.attributes", "tag").build()
128+
);
130129

131130
MetaData.Builder mb = MetaData.builder();
132131
for (int i = 1; i <= numIndices; i++) {
133-
mb.put(IndexMetaData.builder("test_" + i)
132+
mb.put(
133+
IndexMetaData.builder("test_" + i)
134134
.settings(Settings.builder().put("index.version.created", Version.CURRENT))
135135
.numberOfShards(numShards)
136136
.numberOfReplicas(numReplicas)
@@ -147,8 +147,10 @@ public void setUp() throws Exception {
147147
nb.add(Allocators.newNode("node" + i, Collections.singletonMap("tag", "tag_" + (i % numTags))));
148148
}
149149
initialClusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
150-
.metaData(metaData).routingTable(routingTable).nodes
151-
(nb).build();
150+
.metaData(metaData)
151+
.routingTable(routingTable)
152+
.nodes(nb)
153+
.build();
152154
}
153155

154156
private int toInt(String v) {
@@ -159,8 +161,10 @@ private int toInt(String v) {
159161
public ClusterState measureAllocation() {
160162
ClusterState clusterState = initialClusterState;
161163
while (clusterState.getRoutingNodes().hasUnassignedShards()) {
162-
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes()
163-
.shardsWithState(ShardRoutingState.INITIALIZING));
164+
clusterState = strategy.applyStartedShards(
165+
clusterState,
166+
clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING)
167+
);
164168
clusterState = strategy.reroute(clusterState, "reroute");
165169
}
166170
return clusterState;

benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/Allocators.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.elasticsearch.common.util.set.Sets;
3737
import org.elasticsearch.gateway.GatewayAllocator;
3838

39-
import java.lang.reflect.InvocationTargetException;
4039
import java.util.Collection;
4140
import java.util.Collections;
4241
import java.util.List;
@@ -67,33 +66,34 @@ private Allocators() {
6766
throw new AssertionError("Do not instantiate");
6867
}
6968

70-
71-
public static AllocationService createAllocationService(Settings settings) throws NoSuchMethodException, InstantiationException,
72-
IllegalAccessException, InvocationTargetException {
73-
return createAllocationService(settings, new ClusterSettings(Settings.EMPTY, ClusterSettings
74-
.BUILT_IN_CLUSTER_SETTINGS));
69+
public static AllocationService createAllocationService(Settings settings) {
70+
return createAllocationService(settings, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
7571
}
7672

77-
public static AllocationService createAllocationService(Settings settings, ClusterSettings clusterSettings) throws
78-
InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
73+
public static AllocationService createAllocationService(Settings settings, ClusterSettings clusterSettings) {
7974
return new AllocationService(
8075
defaultAllocationDeciders(settings, clusterSettings),
81-
NoopGatewayAllocator.INSTANCE, new BalancedShardsAllocator(settings), EmptyClusterInfoService.INSTANCE);
76+
NoopGatewayAllocator.INSTANCE,
77+
new BalancedShardsAllocator(settings),
78+
EmptyClusterInfoService.INSTANCE
79+
);
8280
}
8381

84-
public static AllocationDeciders defaultAllocationDeciders(Settings settings, ClusterSettings clusterSettings) throws
85-
IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException {
86-
Collection<AllocationDecider> deciders =
87-
ClusterModule.createAllocationDeciders(settings, clusterSettings, Collections.emptyList());
82+
public static AllocationDeciders defaultAllocationDeciders(Settings settings, ClusterSettings clusterSettings) {
83+
Collection<AllocationDecider> deciders = ClusterModule.createAllocationDeciders(settings, clusterSettings, Collections.emptyList());
8884
return new AllocationDeciders(deciders);
89-
9085
}
9186

9287
private static final AtomicInteger portGenerator = new AtomicInteger();
9388

9489
public static DiscoveryNode newNode(String nodeId, Map<String, String> attributes) {
95-
return new DiscoveryNode("", nodeId, new TransportAddress(TransportAddress.META_ADDRESS,
96-
portGenerator.incrementAndGet()), attributes, Sets.newHashSet(DiscoveryNodeRole.MASTER_ROLE,
97-
DiscoveryNodeRole.DATA_ROLE), Version.CURRENT);
90+
return new DiscoveryNode(
91+
"",
92+
nodeId,
93+
new TransportAddress(TransportAddress.META_ADDRESS, portGenerator.incrementAndGet()),
94+
attributes,
95+
Sets.newHashSet(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE),
96+
Version.CURRENT
97+
);
9898
}
9999
}

benchmarks/src/main/java/org/elasticsearch/benchmark/time/DateFormatterBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
@BenchmarkMode(Mode.AverageTime)
4040
@OutputTimeUnit(TimeUnit.NANOSECONDS)
4141
@State(Scope.Benchmark)
42-
@SuppressWarnings("unused") //invoked by benchmarking framework
42+
@SuppressWarnings("unused") // invoked by benchmarking framework
4343
public class DateFormatterBenchmark {
4444

4545
private final DateFormatter javaFormatter = DateFormatter.forPattern("8year_month_day||ordinal_date||epoch_millis");

benchmarks/src/main/java/org/elasticsearch/benchmark/time/DateFormatterFromBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
@BenchmarkMode(Mode.AverageTime)
4040
@OutputTimeUnit(TimeUnit.NANOSECONDS)
4141
@State(Scope.Benchmark)
42-
@SuppressWarnings("unused") //invoked by benchmarking framework
42+
@SuppressWarnings("unused") // invoked by benchmarking framework
4343
public class DateFormatterFromBenchmark {
4444

4545
private final TemporalAccessor accessor = DateFormatter.forPattern("epoch_millis").parse("1234567890");

benchmarks/src/main/java/org/elasticsearch/benchmark/time/RoundingBenchmark.java

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@
4848
@BenchmarkMode(Mode.AverageTime)
4949
@OutputTimeUnit(TimeUnit.NANOSECONDS)
5050
@State(Scope.Benchmark)
51-
@SuppressWarnings("unused") //invoked by benchmarking framework
51+
@SuppressWarnings("unused") // invoked by benchmarking framework
5252
public class RoundingBenchmark {
5353

5454
private final ZoneId zoneId = ZoneId.of("Europe/Amsterdam");
5555
private final DateTimeZone timeZone = DateUtils.zoneIdToDateTimeZone(zoneId);
5656

5757
private long timestamp = 1548879021354L;
5858

59-
private final org.elasticsearch.common.rounding.Rounding jodaRounding =
60-
org.elasticsearch.common.rounding.Rounding.builder(DateTimeUnit.HOUR_OF_DAY).timeZone(timeZone).build();
61-
private final Rounding javaRounding = Rounding.builder(Rounding.DateTimeUnit.HOUR_OF_DAY)
62-
.timeZone(zoneId).build();
59+
private final org.elasticsearch.common.rounding.Rounding jodaRounding = org.elasticsearch.common.rounding.Rounding.builder(
60+
DateTimeUnit.HOUR_OF_DAY
61+
).timeZone(timeZone).build();
62+
private final Rounding javaRounding = Rounding.builder(Rounding.DateTimeUnit.HOUR_OF_DAY).timeZone(zoneId).build();
6363

6464
@Benchmark
6565
public long timeRoundingDateTimeUnitJoda() {
@@ -71,10 +71,10 @@ public long timeRoundingDateTimeUnitJava() {
7171
return javaRounding.round(timestamp);
7272
}
7373

74-
private final org.elasticsearch.common.rounding.Rounding jodaDayOfMonthRounding =
75-
org.elasticsearch.common.rounding.Rounding.builder(DateTimeUnit.DAY_OF_MONTH).timeZone(timeZone).build();
76-
private final Rounding javaDayOfMonthRounding = Rounding.builder(DAY_OF_MONTH)
77-
.timeZone(zoneId).build();
74+
private final org.elasticsearch.common.rounding.Rounding jodaDayOfMonthRounding = org.elasticsearch.common.rounding.Rounding.builder(
75+
DateTimeUnit.DAY_OF_MONTH
76+
).timeZone(timeZone).build();
77+
private final Rounding javaDayOfMonthRounding = Rounding.builder(DAY_OF_MONTH).timeZone(zoneId).build();
7878

7979
@Benchmark
8080
public long timeRoundingDateTimeUnitDayOfMonthJoda() {
@@ -86,10 +86,10 @@ public long timeRoundingDateTimeUnitDayOfMonthJava() {
8686
return javaDayOfMonthRounding.round(timestamp);
8787
}
8888

89-
private final org.elasticsearch.common.rounding.Rounding timeIntervalRoundingJoda =
90-
org.elasticsearch.common.rounding.Rounding.builder(TimeValue.timeValueMinutes(60)).timeZone(timeZone).build();
91-
private final Rounding timeIntervalRoundingJava = Rounding.builder(TimeValue.timeValueMinutes(60))
92-
.timeZone(zoneId).build();
89+
private final org.elasticsearch.common.rounding.Rounding timeIntervalRoundingJoda = org.elasticsearch.common.rounding.Rounding.builder(
90+
TimeValue.timeValueMinutes(60)
91+
).timeZone(timeZone).build();
92+
private final Rounding timeIntervalRoundingJava = Rounding.builder(TimeValue.timeValueMinutes(60)).timeZone(zoneId).build();
9393

9494
@Benchmark
9595
public long timeIntervalRoundingJava() {
@@ -101,10 +101,11 @@ public long timeIntervalRoundingJoda() {
101101
return timeIntervalRoundingJoda.round(timestamp);
102102
}
103103

104-
private final org.elasticsearch.common.rounding.Rounding timeUnitRoundingUtcDayOfMonthJoda =
105-
org.elasticsearch.common.rounding.Rounding.builder(DateTimeUnit.DAY_OF_MONTH).timeZone(DateTimeZone.UTC).build();
106-
private final Rounding timeUnitRoundingUtcDayOfMonthJava = Rounding.builder(DAY_OF_MONTH)
107-
.timeZone(ZoneOffset.UTC).build();
104+
private final org.elasticsearch.common.rounding.Rounding timeUnitRoundingUtcDayOfMonthJoda = org.elasticsearch.common.rounding.Rounding
105+
.builder(DateTimeUnit.DAY_OF_MONTH)
106+
.timeZone(DateTimeZone.UTC)
107+
.build();
108+
private final Rounding timeUnitRoundingUtcDayOfMonthJava = Rounding.builder(DAY_OF_MONTH).timeZone(ZoneOffset.UTC).build();
108109

109110
@Benchmark
110111
public long timeUnitRoundingUtcDayOfMonthJava() {
@@ -118,8 +119,7 @@ public long timeUnitRoundingUtcDayOfMonthJoda() {
118119

119120
private final org.elasticsearch.common.rounding.Rounding timeUnitRoundingUtcQuarterOfYearJoda =
120121
org.elasticsearch.common.rounding.Rounding.builder(DateTimeUnit.QUARTER).timeZone(DateTimeZone.UTC).build();
121-
private final Rounding timeUnitRoundingUtcQuarterOfYearJava = Rounding.builder(QUARTER_OF_YEAR)
122-
.timeZone(ZoneOffset.UTC).build();
122+
private final Rounding timeUnitRoundingUtcQuarterOfYearJava = Rounding.builder(QUARTER_OF_YEAR).timeZone(ZoneOffset.UTC).build();
123123

124124
@Benchmark
125125
public long timeUnitRoundingUtcQuarterOfYearJava() {
@@ -131,10 +131,11 @@ public long timeUnitRoundingUtcQuarterOfYearJoda() {
131131
return timeUnitRoundingUtcQuarterOfYearJoda.round(timestamp);
132132
}
133133

134-
private final org.elasticsearch.common.rounding.Rounding timeUnitRoundingUtcMonthOfYearJoda =
135-
org.elasticsearch.common.rounding.Rounding.builder(DateTimeUnit.MONTH_OF_YEAR).timeZone(DateTimeZone.UTC).build();
136-
private final Rounding timeUnitRoundingUtcMonthOfYearJava = Rounding.builder(MONTH_OF_YEAR)
137-
.timeZone(ZoneOffset.UTC).build();
134+
private final org.elasticsearch.common.rounding.Rounding timeUnitRoundingUtcMonthOfYearJoda = org.elasticsearch.common.rounding.Rounding
135+
.builder(DateTimeUnit.MONTH_OF_YEAR)
136+
.timeZone(DateTimeZone.UTC)
137+
.build();
138+
private final Rounding timeUnitRoundingUtcMonthOfYearJava = Rounding.builder(MONTH_OF_YEAR).timeZone(ZoneOffset.UTC).build();
138139

139140
@Benchmark
140141
public long timeUnitRoundingUtcMonthOfYearJava() {
@@ -146,11 +147,9 @@ public long timeUnitRoundingUtcMonthOfYearJoda() {
146147
return timeUnitRoundingUtcMonthOfYearJoda.round(timestamp);
147148
}
148149

149-
150150
private final org.elasticsearch.common.rounding.Rounding timeUnitRoundingUtcYearOfCenturyJoda =
151151
org.elasticsearch.common.rounding.Rounding.builder(DateTimeUnit.YEAR_OF_CENTURY).timeZone(DateTimeZone.UTC).build();
152-
private final Rounding timeUnitRoundingUtcYearOfCenturyJava = Rounding.builder(YEAR_OF_CENTURY)
153-
.timeZone(ZoneOffset.UTC).build();
152+
private final Rounding timeUnitRoundingUtcYearOfCenturyJava = Rounding.builder(YEAR_OF_CENTURY).timeZone(ZoneOffset.UTC).build();
154153

155154
@Benchmark
156155
public long timeUnitRoundingUtcYearOfCenturyJava() {

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,12 @@ subprojects {
108108
// is greater than the number of unformatted projects, this can be
109109
// switched to an exclude list, and eventually removed completely.
110110
def projectPathsToFormat = [
111+
':benchmarks',
111112
':build-tools',
112113
':distribution:tools:java-version-checker',
113114
':distribution:tools:launchers',
114115
':distribution:tools:plugin-cli',
116+
':qa:os',
115117
':x-pack:plugin:enrich'
116118
]
117119

0 commit comments

Comments
 (0)