Skip to content

Commit

Permalink
[COMMON] apply Configuration#EMPTY to code base (opensource4you#1797)
Browse files Browse the repository at this point in the history
  • Loading branch information
chia7712 authored May 31, 2023
1 parent 0118432 commit a556180
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static org.astraea.common.cost.CostUtils.changedRecordSizeOverflow;

import java.util.Map;
import java.util.stream.Collectors;
import org.astraea.common.Configuration;
import org.astraea.common.DataSize;
Expand All @@ -33,7 +32,7 @@ public class RecordSizeCost
public static final String MAX_MIGRATE_SIZE_KEY = "max.migrated.size";

public RecordSizeCost() {
this.config = new Configuration(Map.of());
this.config = Configuration.EMPTY;
}

public RecordSizeCost(Configuration config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ReplicaLeaderCost implements HasBrokerCost, HasClusterCost, HasMove
public static final String MAX_MIGRATE_LEADER_KEY = "max.migrated.leader.number";

public ReplicaLeaderCost() {
this.config = new Configuration(Map.of());
this.config = Configuration.EMPTY;
}

public ReplicaLeaderCost(Configuration config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static org.astraea.common.cost.CostUtils.changedRecordSizeOverflow;

import java.util.Map;
import java.util.stream.Collectors;
import org.astraea.common.Configuration;
import org.astraea.common.DataSize;
Expand All @@ -39,7 +38,7 @@ public class ReplicaLeaderSizeCost
public static final String MOVED_LEADER_SIZE = "moved leader size (bytes)";

public ReplicaLeaderSizeCost() {
this.config = new Configuration(Map.of());
this.config = Configuration.EMPTY;
}

public ReplicaLeaderSizeCost(Configuration config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static org.astraea.common.cost.MigrationCost.replicaNumChanged;

import java.util.Map;
import java.util.stream.Collectors;
import org.astraea.common.Configuration;
import org.astraea.common.admin.Broker;
Expand All @@ -32,7 +31,7 @@ public class ReplicaNumberCost implements HasClusterCost, HasMoveCost {
private final Configuration config;

public ReplicaNumberCost() {
this.config = new Configuration(Map.of());
this.config = Configuration.EMPTY;
}

public ReplicaNumberCost(Configuration config) {
Expand Down
4 changes: 2 additions & 2 deletions common/src/test/java/org/astraea/common/UtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public int value() {
@ParameterizedTest
@ValueSource(classes = {TestCostFunction.class, TestConfigCostFunction.class})
void testConstruct(Class<? extends CostFunction> aClass) {
var config = new Configuration(Map.of());
var config = Configuration.EMPTY;

var costFunction = Utils.construct(aClass, config);
Assertions.assertInstanceOf(CostFunction.class, costFunction);
Expand All @@ -226,7 +226,7 @@ void testConstruct(Class<? extends CostFunction> aClass) {
void testConstructException() {
// arrange
var aClass = TestBadCostFunction.class;
var config = new Configuration(Map.of());
var config = Configuration.EMPTY;

// act, assert
Assertions.assertThrows(RuntimeException.class, () -> Utils.construct(aClass, config));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void testConfig() {

@Test
void testJmx() {
var cost = new DecreasingCost(new Configuration(Map.of()));
var cost = new DecreasingCost(Configuration.EMPTY);
var id = "TestJmx-" + UUID.randomUUID();
var clusterInfo = FakeClusterInfo.of(5, 5, 5, 2);
var balancer =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class StrictCostPartitionerTest {
@Test
void testJmxPort() {
try (var partitioner = new StrictCostPartitioner()) {
partitioner.configure(new Configuration(Map.of()));
partitioner.configure(Configuration.EMPTY);
Assertions.assertThrows(
NoSuchElementException.class, () -> partitioner.jmxPortGetter.apply(0));
partitioner.configure(new Configuration(Map.of(StrictCostPartitioner.JMX_PORT, "12345")));
Expand Down Expand Up @@ -208,7 +208,7 @@ void testReturnedPartition() {
@Test
void testDefaultFunction() {
try (var partitioner = new StrictCostPartitioner()) {
partitioner.configure(new Configuration(Map.of()));
partitioner.configure(Configuration.EMPTY);
Assertions.assertNotEquals(HasBrokerCost.EMPTY, partitioner.costFunction);
Utils.waitFor(() -> partitioner.metricStore.sensors().size() == 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected Class<? extends SourceTask> task() {
@Override
protected List<Configuration> takeConfiguration(int maxTasks) {
return IntStream.range(0, maxTasks)
.mapToObj(i -> new Configuration(Map.of()))
.mapToObj(i -> Configuration.EMPTY)
.collect(Collectors.toList());
}

Expand Down Expand Up @@ -166,7 +166,7 @@ protected Class<? extends SinkTask> task() {
@Override
protected List<Configuration> takeConfiguration(int maxTasks) {
return IntStream.range(0, maxTasks)
.mapToObj(i -> new Configuration(Map.of()))
.mapToObj(i -> Configuration.EMPTY)
.collect(Collectors.toList());
}

Expand Down

0 comments on commit a556180

Please sign in to comment.