diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-12-21 16:52:16 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-12-21 16:52:16 +0100 |
commit | c7a1a7e1f36a45eac22837937c683b008adbe51d (patch) | |
tree | 4e67f870efa53ad87e0d5ac641ed288c451349c7 /clustercontroller-core | |
parent | e0fb5474ac171436e263a4950d72a2a405d379a2 (diff) |
GC use of deprecated junit assertThat and unify
Diffstat (limited to 'clustercontroller-core')
15 files changed, 84 insertions, 104 deletions
diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ClusterStateGeneratorTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ClusterStateGeneratorTest.java index 15b59e4e8e4..f857bfcee89 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ClusterStateGeneratorTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ClusterStateGeneratorTest.java @@ -17,7 +17,7 @@ import static com.yahoo.vespa.clustercontroller.core.matchers.HasStateReasonForN import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class ClusterStateGeneratorTest { diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ContentClusterHtmlRendererTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ContentClusterHtmlRendererTest.java index 8e00593587a..ff1c5b0bb17 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ContentClusterHtmlRendererTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ContentClusterHtmlRendererTest.java @@ -16,7 +16,7 @@ import java.util.Collections; import java.util.TreeMap; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.mock; public class ContentClusterHtmlRendererTest { diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/DatabaseHandlerTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/DatabaseHandlerTest.java index 35431703824..a621b0f565a 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/DatabaseHandlerTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/DatabaseHandlerTest.java @@ -8,8 +8,7 @@ import com.yahoo.vespa.clustercontroller.core.listeners.NodeAddedOrRemovedListen import com.yahoo.vespa.clustercontroller.core.listeners.NodeStateOrHostInfoChangeHandler; import org.junit.Test; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; @@ -90,7 +89,7 @@ public class DatabaseHandlerTest { when(f.mockDatabase.retrieveLastPublishedStateBundle()).thenReturn(f.dummyBundle); ClusterStateBundle retrievedBundle = handler.getLatestClusterStateBundle(); - assertThat(retrievedBundle, equalTo(f.dummyBundle)); + assertEquals(f.dummyBundle, retrievedBundle); } // FIXME I don't like the semantics of this, but it mirrors the legacy behavior for the @@ -102,7 +101,7 @@ public class DatabaseHandlerTest { // Note: no DB setup step ClusterStateBundle retrievedBundle = handler.getLatestClusterStateBundle(); - assertThat(retrievedBundle, equalTo(ClusterStateBundle.empty())); + assertEquals(ClusterStateBundle.empty(), retrievedBundle); } } diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/EventDiffCalculatorTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/EventDiffCalculatorTest.java index a616f823ad0..48d6ccbf655 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/EventDiffCalculatorTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/EventDiffCalculatorTest.java @@ -12,7 +12,7 @@ import static com.yahoo.vespa.clustercontroller.core.matchers.EventTypeIs.eventT import static com.yahoo.vespa.clustercontroller.core.matchers.EventTimeIs.eventTimeIs; import static org.hamcrest.CoreMatchers.allOf; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.CoreMatchers.hasItem; import static com.yahoo.vespa.clustercontroller.core.ClusterFixture.storageNode; diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/GroupAutoTakedownTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/GroupAutoTakedownTest.java index a3bc39bde39..254f863e9ea 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/GroupAutoTakedownTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/GroupAutoTakedownTest.java @@ -20,7 +20,7 @@ import java.util.Set; import static org.hamcrest.core.AllOf.allOf; import static org.hamcrest.core.IsCollectionContaining.hasItem; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/GroupAvailabilityCalculatorTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/GroupAvailabilityCalculatorTest.java index a533cd35f94..a5357e0a639 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/GroupAvailabilityCalculatorTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/GroupAvailabilityCalculatorTest.java @@ -11,7 +11,7 @@ import java.util.List; import java.util.Set; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class GroupAvailabilityCalculatorTest { diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/LeafGroupsTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/LeafGroupsTest.java index cfcaf1ce0c5..418400b3fff 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/LeafGroupsTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/LeafGroupsTest.java @@ -7,7 +7,7 @@ import org.junit.Test; import java.util.List; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class LeafGroupsTest { diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/MaintenanceWhenPendingGlobalMergesTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/MaintenanceWhenPendingGlobalMergesTest.java index 4ddf6453981..2f79ad3fa95 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/MaintenanceWhenPendingGlobalMergesTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/MaintenanceWhenPendingGlobalMergesTest.java @@ -10,7 +10,7 @@ import java.util.Arrays; import static com.yahoo.vespa.clustercontroller.core.NodeStateReason.MAY_HAVE_MERGES_PENDING; import static com.yahoo.vespa.clustercontroller.core.NodeStateReason.NODE_TOO_UNSTABLE; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/MasterElectionTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/MasterElectionTest.java index bf3efb17ddf..ab638a1da7d 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/MasterElectionTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/MasterElectionTest.java @@ -25,10 +25,8 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Stream; -import static org.hamcrest.Matchers.greaterThan; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; public class MasterElectionTest extends FleetControllerTest { @@ -504,7 +502,7 @@ public class MasterElectionTest extends FleetControllerTest { final long postElectionVersionNumber = fleetControllers.get(1).getSystemState().getVersion(); - assertThat(postElectionVersionNumber, greaterThan(preElectionVersionNumber)); + assertTrue(postElectionVersionNumber > preElectionVersionNumber); } @Test diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/NodeStateChangeCheckerTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/NodeStateChangeCheckerTest.java index 3a301c52b42..87e102c67c1 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/NodeStateChangeCheckerTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/NodeStateChangeCheckerTest.java @@ -20,12 +20,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.StringContains.containsString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -130,7 +127,7 @@ public class NodeStateChangeCheckerTest { UP_NODE_STATE, MAINTENANCE_NODE_STATE); assertFalse(result.settingWantedStateIsAllowed()); assertFalse(result.wantedStateAlreadySet()); - assertThat(result.getReason(), is("Master cluster controller is bootstrapping and in moratorium")); + assertEquals("Master cluster controller is bootstrapping and in moratorium", result.getReason()); } @Test @@ -143,7 +140,7 @@ public class NodeStateChangeCheckerTest { UP_NODE_STATE, MAINTENANCE_NODE_STATE); assertFalse(result.settingWantedStateIsAllowed()); assertFalse(result.wantedStateAlreadySet()); - assertThat(result.getReason(), is("Unknown node storage.10")); + assertEquals("Unknown node storage.10", result.getReason()); } @Test @@ -162,8 +159,8 @@ public class NodeStateChangeCheckerTest { SetUnitStateRequest.Condition.SAFE, UP_NODE_STATE, MAINTENANCE_NODE_STATE); assertFalse(result.settingWantedStateIsAllowed()); assertFalse(result.wantedStateAlreadySet()); - assertThat(result.getReason(), is("At most one node can have a wanted state when #groups = 1: " + - "Other storage node 0 has wanted state Maintenance")); + assertEquals("At most one node can have a wanted state when #groups = 1: Other storage node 0 has wanted state Maintenance", + result.getReason()); } @Test @@ -183,8 +180,8 @@ public class NodeStateChangeCheckerTest { SetUnitStateRequest.Condition.SAFE, UP_NODE_STATE, MAINTENANCE_NODE_STATE); assertFalse(result.settingWantedStateIsAllowed()); assertFalse(result.wantedStateAlreadySet()); - assertThat(result.getReason(), is("At most one node can have a wanted state when #groups = 1: " + - "Other distributor 0 has wanted state Down")); + assertEquals("At most one node can have a wanted state when #groups = 1: Other distributor 0 has wanted state Down", + result.getReason()); } @Test @@ -208,8 +205,7 @@ public class NodeStateChangeCheckerTest { SetUnitStateRequest.Condition.SAFE, UP_NODE_STATE, MAINTENANCE_NODE_STATE); assertFalse(result.settingWantedStateIsAllowed()); assertFalse(result.wantedStateAlreadySet()); - assertThat(result.getReason(), is("At most one group can have wanted state: " + - "Other distributor 0 in group 0 has wanted state Down")); + assertEquals("At most one group can have wanted state: Other distributor 0 in group 0 has wanted state Down", result.getReason()); } { @@ -243,8 +239,8 @@ public class NodeStateChangeCheckerTest { SetUnitStateRequest.Condition.SAFE, UP_NODE_STATE, MAINTENANCE_NODE_STATE); assertFalse(result.settingWantedStateIsAllowed()); assertFalse(result.wantedStateAlreadySet()); - assertThat(result.getReason(), is("At most one group can have wanted state: " + - "Other storage node 0 in group 0 has wanted state Maintenance")); + assertEquals("At most one group can have wanted state: Other storage node 0 in group 0 has wanted state Maintenance", + result.getReason()); } { @@ -306,7 +302,7 @@ public class NodeStateChangeCheckerTest { UP_NODE_STATE, MAINTENANCE_NODE_STATE); assertFalse(result.settingWantedStateIsAllowed()); assertFalse(result.wantedStateAlreadySet()); - assertThat(result.getReason(), containsString("Safe-set of node state is only supported for storage nodes")); + assertTrue(result.getReason().contains("Safe-set of node state is only supported for storage nodes")); } @Test @@ -327,7 +323,7 @@ public class NodeStateChangeCheckerTest { UP_NODE_STATE, MAINTENANCE_NODE_STATE); assertFalse(result.settingWantedStateIsAllowed()); assertFalse(result.wantedStateAlreadySet()); - assertThat(result.getReason(), is("Another storage node has state DOWN: 3")); + assertEquals("Another storage node has state DOWN: 3", result.getReason()); } @Test @@ -394,8 +390,8 @@ public class NodeStateChangeCheckerTest { UP_NODE_STATE, MAINTENANCE_NODE_STATE); assertFalse(result.settingWantedStateIsAllowed()); assertFalse(result.wantedStateAlreadySet()); - assertThat(result.getReason(), is("Distributor 0 says storage node 1 " + - "has buckets with redundancy as low as 3, but we require at least 4")); + assertEquals("Distributor 0 says storage node 1 has buckets with redundancy as low as 3, but we require at least 4", + result.getReason()); } @Test @@ -445,7 +441,7 @@ public class NodeStateChangeCheckerTest { nodeStorage, defaultAllUpClusterState(), SetUnitStateRequest.Condition.SAFE, UP_NODE_STATE, MAINTENANCE_NODE_STATE); assertFalse(result.settingWantedStateIsAllowed()); assertFalse(result.wantedStateAlreadySet()); - assertThat(result.getReason(), is("Distributor node 0 has not reported any cluster state version yet.")); + assertEquals("Distributor node 0 has not reported any cluster state version yet.", result.getReason()); } private NodeStateChangeChecker.Result transitionToSameState(State state, String oldDescription, String newDescription) { @@ -559,7 +555,7 @@ public class NodeStateChangeCheckerTest { NodeStateChangeChecker.Result result = transitionToMaintenanceWithOneStorageNodeDown(otherIndex); assertFalse(result.settingWantedStateIsAllowed()); assertFalse(result.wantedStateAlreadySet()); - assertThat(result.getReason(), containsString("Another storage node has state DOWN: 2")); + assertTrue(result.getReason().contains("Another storage node has state DOWN: 2")); } @Test diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/StateVersionTrackerTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/StateVersionTrackerTest.java index e98cea72d08..2361a5cefd8 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/StateVersionTrackerTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/StateVersionTrackerTest.java @@ -9,12 +9,10 @@ import com.yahoo.vdslib.state.State; import com.yahoo.vespa.clustercontroller.core.hostinfo.HostInfo; import org.junit.Test; -import java.util.Arrays; +import java.util.List; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -46,34 +44,34 @@ public class StateVersionTrackerTest { final StateVersionTracker versionTracker = createWithMockedMetrics(); versionTracker.setVersionRetrievedFromZooKeeper(100); updateAndPromote(versionTracker, stateWithoutAnnotations("distributor:2 storage:2"), 123); - assertThat(versionTracker.getCurrentVersion(), equalTo(101)); - assertThat(versionTracker.getVersionedClusterState().toString(), equalTo("version:101 distributor:2 storage:2")); + assertEquals(101, versionTracker.getCurrentVersion()); + assertEquals("version:101 distributor:2 storage:2", versionTracker.getVersionedClusterState().toString()); } @Test public void version_is_1_upon_construction() { final StateVersionTracker versionTracker = createWithMockedMetrics(); - assertThat(versionTracker.getCurrentVersion(), equalTo(1)); + assertEquals(1, versionTracker.getCurrentVersion()); } @Test public void set_current_version_caps_lowest_version_to_1() { final StateVersionTracker versionTracker = createWithMockedMetrics(); versionTracker.setVersionRetrievedFromZooKeeper(0); - assertThat(versionTracker.getCurrentVersion(), equalTo(1)); + assertEquals(1, versionTracker.getCurrentVersion()); } @Test public void new_version_from_zk_predicate_initially_false() { final StateVersionTracker versionTracker = createWithMockedMetrics(); - assertThat(versionTracker.hasReceivedNewVersionFromZooKeeper(), is(false)); + assertFalse(versionTracker.hasReceivedNewVersionFromZooKeeper()); } @Test public void new_version_from_zk_predicate_true_after_setting_zk_version() { final StateVersionTracker versionTracker = createWithMockedMetrics(); versionTracker.setVersionRetrievedFromZooKeeper(5); - assertThat(versionTracker.hasReceivedNewVersionFromZooKeeper(), is(true)); + assertTrue(versionTracker.hasReceivedNewVersionFromZooKeeper()); } @Test @@ -81,14 +79,14 @@ public class StateVersionTrackerTest { final StateVersionTracker versionTracker = createWithMockedMetrics(); versionTracker.setVersionRetrievedFromZooKeeper(5); updateAndPromote(versionTracker, stateWithoutAnnotations("distributor:2 storage:2"), 123); - assertThat(versionTracker.hasReceivedNewVersionFromZooKeeper(), is(false)); + assertFalse(versionTracker.hasReceivedNewVersionFromZooKeeper()); } @Test public void exposed_states_are_empty_upon_construction() { final StateVersionTracker versionTracker = createWithMockedMetrics(); - assertThat(versionTracker.getVersionedClusterState().toString(), equalTo("")); - assertThat(versionTracker.getAnnotatedVersionedClusterState().getClusterState().toString(), equalTo("")); + assertTrue(versionTracker.getVersionedClusterState().toString().isEmpty()); + assertTrue(versionTracker.getAnnotatedVersionedClusterState().getClusterState().toString().isEmpty()); } @Test @@ -143,20 +141,20 @@ public class StateVersionTrackerTest { @Test public void lowest_observed_distribution_bit_is_initially_16() { final StateVersionTracker versionTracker = createWithMockedMetrics(); - assertThat(versionTracker.getLowestObservedDistributionBits(), equalTo(16)); + assertEquals(16, versionTracker.getLowestObservedDistributionBits()); } @Test public void lowest_observed_distribution_bit_is_tracked_across_states() { final StateVersionTracker versionTracker = createWithMockedMetrics(); updateAndPromote(versionTracker, stateWithoutAnnotations("bits:15 distributor:2 storage:2"), 100); - assertThat(versionTracker.getLowestObservedDistributionBits(), equalTo(15)); + assertEquals(15, versionTracker.getLowestObservedDistributionBits()); updateAndPromote(versionTracker, stateWithoutAnnotations("bits:17 distributor:2 storage:2"), 200); - assertThat(versionTracker.getLowestObservedDistributionBits(), equalTo(15)); + assertEquals(15, versionTracker.getLowestObservedDistributionBits()); updateAndPromote(versionTracker, stateWithoutAnnotations("bits:14 distributor:2 storage:2"), 300); - assertThat(versionTracker.getLowestObservedDistributionBits(), equalTo(14)); + assertEquals(14, versionTracker.getLowestObservedDistributionBits()); } // For similarity purposes, only the cluster-wide bits matter, not the individual node state @@ -201,11 +199,8 @@ public class StateVersionTrackerTest { String s2 = "version:2 distributor:2 storage:2"; // Note: newest entry first - assertThat(versionTracker.getClusterStateHistory(), - equalTo(Arrays.asList( - historyEntry(s4, s3, 300), - historyEntry(s3, s2, 200), - historyEntry(s2, 100)))); + assertEquals(List.of(historyEntry(s4, s3, 300), historyEntry(s3, s2, 200), historyEntry(s2, 100)), + versionTracker.getClusterStateHistory()); } @Test @@ -222,17 +217,13 @@ public class StateVersionTrackerTest { String s3 = "version:3 distributor:3 storage:3"; String s2 = "version:2 distributor:2 storage:2"; - assertThat(versionTracker.getClusterStateHistory(), - equalTo(Arrays.asList( - historyEntry(s4, s3, 300), - historyEntry(s3, s2, 200)))); + assertEquals(List.of(historyEntry(s4, s3, 300), historyEntry(s3, s2, 200)), + versionTracker.getClusterStateHistory()); updateAndPromote(versionTracker, stateWithoutAnnotations("distributor:5 storage:5"), 400); - assertThat(versionTracker.getClusterStateHistory(), - equalTo(Arrays.asList( - historyEntry(s5, s4, 400), - historyEntry(s4, s3, 300)))); + assertEquals(List.of(historyEntry(s5, s4, 400), historyEntry(s4, s3, 300)), + versionTracker.getClusterStateHistory()); } @Test @@ -241,11 +232,11 @@ public class StateVersionTrackerTest { AnnotatedClusterState candidate = stateWithoutAnnotations("distributor:2 storage:2"); versionTracker.updateLatestCandidateStateBundle(ClusterStateBundle.ofBaselineOnly(candidate)); - assertThat(versionTracker.getLatestCandidateState(), equalTo(candidate)); + assertEquals(candidate, versionTracker.getLatestCandidateState()); candidate = stateWithoutAnnotations("distributor:3 storage:3"); versionTracker.updateLatestCandidateStateBundle(ClusterStateBundle.ofBaselineOnly(candidate)); - assertThat(versionTracker.getLatestCandidateState(), equalTo(candidate)); + assertEquals(candidate, versionTracker.getLatestCandidateState()); } private static ClusterState stateOf(String state) { @@ -327,9 +318,9 @@ public class StateVersionTrackerTest { versionTracker.setVersionRetrievedFromZooKeeper(200); versionTracker.setClusterStateBundleRetrievedFromZooKeeper(zkBundle); - assertThat(versionTracker.getLatestCandidateState(), equalTo(AnnotatedClusterState.emptyState())); - assertThat(versionTracker.getVersionedClusterStateBundle(), equalTo(zkBundle)); - assertThat(versionTracker.getCurrentVersion(), equalTo(200)); // Not from bundle, but from explicitly stored version + assertEquals(AnnotatedClusterState.emptyState(), versionTracker.getLatestCandidateState()); + assertEquals(zkBundle, versionTracker.getVersionedClusterStateBundle()); + assertEquals(200, versionTracker.getCurrentVersion()); // Not from bundle, but from explicitly stored version } private HostInfo createHostInfo(long bucketsPending) { diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ZooKeeperDatabaseTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ZooKeeperDatabaseTest.java index a71665fb364..7d64a8f8878 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ZooKeeperDatabaseTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/ZooKeeperDatabaseTest.java @@ -11,12 +11,12 @@ import org.junit.rules.ExpectedException; import java.io.IOException; import java.time.Duration; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; public class ZooKeeperDatabaseTest { + @SuppressWarnings("deprecation") @Rule public ExpectedException expectedException = ExpectedException.none(); @@ -66,7 +66,7 @@ public class ZooKeeperDatabaseTest { f.db().storeLastPublishedStateBundle(bundleToStore); ClusterStateBundle bundleReceived = f.db().retrieveLastPublishedStateBundle(); - assertThat(bundleReceived, equalTo(bundleToStore)); + assertEquals(bundleToStore, bundleReceived); } } @@ -102,7 +102,7 @@ public class ZooKeeperDatabaseTest { f.createDatabase(); ClusterStateBundle bundleReceived = f.db().retrieveLastPublishedStateBundle(); - assertThat(bundleReceived, equalTo(ClusterStateBundle.empty())); + assertEquals(ClusterStateBundle.empty(), bundleReceived); } } diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/hostinfo/HostInfoTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/hostinfo/HostInfoTest.java index 98fc879adbc..b5ad82b6b0c 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/hostinfo/HostInfoTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/hostinfo/HostInfoTest.java @@ -13,13 +13,9 @@ import java.util.Map; import java.util.Optional; import java.util.TreeMap; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; public class HostInfoTest { @@ -35,41 +31,40 @@ public class HostInfoTest { @Test public void testEmptyJson() { HostInfo hostInfo = HostInfo.createHostInfo("{}"); - assertThat(hostInfo.getVtag().getVersionOrNull(), is(nullValue())); - assertThat(hostInfo.getDistributor().getStorageNodes().size(), is(0)); - assertThat(hostInfo.getContentNode().getResourceUsage().size(), is(0)); - assertThat(hostInfo.getMetrics().getMetrics().size(), is(0)); - assertThat(hostInfo.getClusterStateVersionOrNull(), is(nullValue())); + assertNull(hostInfo.getVtag().getVersionOrNull()); + assertTrue(hostInfo.getDistributor().getStorageNodes().isEmpty()); + assertTrue(hostInfo.getContentNode().getResourceUsage().isEmpty()); + assertTrue(hostInfo.getMetrics().getMetrics().isEmpty()); + assertNull(hostInfo.getClusterStateVersionOrNull()); } @Test public void testExtendedJson() throws IOException { HostInfo hostInfo = HostInfo.createHostInfo(readDataFile("host_info.json")); - assertThat(hostInfo.getVtag().getVersionOrNull(), is("5.32.76")); + assertEquals("5.32.76", hostInfo.getVtag().getVersionOrNull()); } @Test public void testFullSet() throws IOException { HostInfo hostInfo = HostInfo.createHostInfo(readDataFile("host_info.json")); List<StorageNode> storageNodeList = hostInfo.getDistributor().getStorageNodes(); - assertThat(storageNodeList.size(), is(2)); - assertThat(storageNodeList.get(0).getIndex(), is(0)); + assertEquals(2, storageNodeList.size()); + assertEquals(0, storageNodeList.get(0).getIndex().intValue()); List<Metrics.Metric> metrics = hostInfo.getMetrics().getMetrics(); - assertThat(metrics.size(), is(4)); - assertThat(metrics.get(0).getValue().getLast(), is(5095L)); - assertThat(metrics.get(0).getName(), equalTo("vds.datastored.alldisks.buckets")); - assertThat(metrics.get(3).getValue().getLast(), is(129L)); - assertThat(metrics.get(3).getName(), equalTo("vds.datastored.bucket_space.buckets_total")); - assertThat(hostInfo.getClusterStateVersionOrNull(), is(123)); - - assertThat(hostInfo.getMetrics() + assertEquals(4, metrics.size()); + assertEquals(5095L, metrics.get(0).getValue().getLast().longValue()); + assertEquals("vds.datastored.alldisks.buckets", metrics.get(0).getName()); + assertEquals(129L, metrics.get(3).getValue().getLast().longValue()); + assertEquals("vds.datastored.bucket_space.buckets_total", metrics.get(3).getName()); + assertEquals(123, hostInfo.getClusterStateVersionOrNull().intValue()); + + assertEquals(Optional.of(129L), hostInfo.getMetrics() .getValueAt("vds.datastored.bucket_space.buckets_total", Map.of("bucketSpace", "default")) - .map(Metrics.Value::getLast), - equalTo(Optional.of(129L))); - assertThat(hostInfo.getMetrics() + .map(Metrics.Value::getLast)); + assertEquals(Optional.of(0L), + hostInfo.getMetrics() .getValueAt("vds.datastored.bucket_space.buckets_total", Map.of("bucketSpace", "global")) - .map(Metrics.Value::getLast), - equalTo(Optional.of(0L))); + .map(Metrics.Value::getLast)); var resourceUsage = hostInfo.getContentNode().getResourceUsage(); assertEquals(resourceUsage.size(), 2); @@ -102,7 +97,7 @@ public class HostInfoTest { HostInfo hostInfo = HostInfo.createHostInfo(json); List<StorageNode> storageNodeList = hostInfo.getDistributor().getStorageNodes(); - assertThat(storageNodeList.size(), is(2)); + assertEquals(2, storageNodeList.size()); Map<Integer, StorageNode> storageNodeByIndex = new TreeMap<>(); for (StorageNode node : storageNodeList) { Integer index = node.getIndex(); @@ -111,11 +106,11 @@ public class HostInfoTest { } assertTrue(storageNodeByIndex.containsKey(0)); - assertThat(storageNodeByIndex.get(0).getIndex(), is(0)); - assertThat(storageNodeByIndex.get(0).getMinCurrentReplicationFactorOrNull(), is(2)); + assertEquals(0, storageNodeByIndex.get(0).getIndex().intValue()); + assertEquals(2, storageNodeByIndex.get(0).getMinCurrentReplicationFactorOrNull().intValue()); assertTrue(storageNodeByIndex.containsKey(5)); - assertThat(storageNodeByIndex.get(5).getIndex(), is(5)); - assertThat(storageNodeByIndex.get(5).getMinCurrentReplicationFactorOrNull(), is(9)); + assertEquals(5, storageNodeByIndex.get(5).getIndex().intValue()); + assertEquals(9, storageNodeByIndex.get(5).getMinCurrentReplicationFactorOrNull().intValue()); } } diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/SetNodeStateTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/SetNodeStateTest.java index 086098514e2..685ad3f0b43 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/SetNodeStateTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/SetNodeStateTest.java @@ -44,6 +44,7 @@ import static org.mockito.Mockito.when; public class SetNodeStateTest extends StateRestApiTest { + @SuppressWarnings("deprecation") @Rule public ExpectedException expectedException = ExpectedException.none(); diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/rpc/SlimeClusterStateBundleCodecTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/rpc/SlimeClusterStateBundleCodecTest.java index 8fc5e8ac208..3d3347acb2d 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/rpc/SlimeClusterStateBundleCodecTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/rpc/SlimeClusterStateBundleCodecTest.java @@ -8,7 +8,7 @@ import org.junit.Test; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.Matchers.lessThan; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class SlimeClusterStateBundleCodecTest { @@ -45,7 +45,7 @@ public class SlimeClusterStateBundleCodecTest { } // Exact same state set string repeated twice; perfect compression fodder. return ClusterStateBundleUtil.makeBundle(String.format("distributor:100%s storage:100%s", - allDownStates.toString(), allDownStates.toString())); + allDownStates, allDownStates)); } @Test |