* ONAP
* ================================================================================
* Copyright (C) 2018, 2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation
+ * Modifications Copyright (C) 2020, 2024 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.drools.pooling.state;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import java.util.Arrays;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.drools.pooling.message.BucketAssignments;
import org.onap.policy.drools.pooling.message.Heartbeat;
import org.onap.policy.drools.pooling.message.Leader;
import org.onap.policy.drools.pooling.message.Offline;
import org.onap.policy.drools.pooling.message.Query;
-public class ActiveStateTest extends SupportBasicStateTester {
+class ActiveStateTest extends SupportBasicStateTester {
private ActiveState state;
* Setup.
*/
@Override
- @Before
+ @BeforeEach
public void setUp() throws Exception {
super.setUp();
}
@Test
- public void testStart() {
+ void testStart() {
state.start();
// ensure the timers were created
}
@Test
- public void testProcessHeartbeat_NullHost() {
+ void testProcessHeartbeat_NullHost() {
assertNull(state.process(new Heartbeat()));
assertFalse(state.isMyHeartbeatSeen());
}
@Test
- public void testProcessHeartbeat_MyHost() {
+ void testProcessHeartbeat_MyHost() {
assertNull(state.process(new Heartbeat(MY_HOST, 0L)));
assertTrue(state.isMyHeartbeatSeen());
}
@Test
- public void testProcessHeartbeat_Predecessor() {
+ void testProcessHeartbeat_Predecessor() {
assertNull(state.process(new Heartbeat(HOST2, 0L)));
assertFalse(state.isMyHeartbeatSeen());
}
@Test
- public void testProcessHeartbeat_OtherHost() {
+ void testProcessHeartbeat_OtherHost() {
assertNull(state.process(new Heartbeat(HOST3, 0L)));
assertFalse(state.isMyHeartbeatSeen());
}
@Test
- public void testProcessOffline_NullHost() {
+ void testProcessOffline_NullHost() {
// should be ignored
assertNull(state.process(new Offline()));
}
@Test
- public void testProcessOffline_UnassignedHost() {
+ void testProcessOffline_UnassignedHost() {
// HOST4 is not in the assignment list - should be ignored
assertNull(state.process(new Offline(HOST4)));
}
@Test
- public void testProcessOffline_IAmLeader() {
+ void testProcessOffline_IAmLeader() {
// configure the next state
State next = mock(State.class);
when(mgr.goActive()).thenReturn(next);
}
@Test
- public void testProcessOffline_PredecessorIsLeaderNowOffline() {
+ void testProcessOffline_PredecessorIsLeaderNowOffline() {
// configure the next state
State next = mock(State.class);
when(mgr.goActive()).thenReturn(next);
}
@Test
- public void testProcessOffline__PredecessorIsNotLeaderNowOffline() {
+ void testProcessOffline__PredecessorIsNotLeaderNowOffline() {
// I am not the leader, and neither is my predecessor
mgr.startDistributing(new BucketAssignments(new String[] {PREV_HOST, MY_HOST, PREV_HOST2}));
state = new ActiveState(mgr);
}
@Test
- public void testProcessOffline_OtherAssignedHostOffline() {
+ void testProcessOffline_OtherAssignedHostOffline() {
// I am not the leader
mgr.startDistributing(new BucketAssignments(new String[] {PREV_HOST, MY_HOST, HOST1}));
state = new ActiveState(mgr);
}
@Test
- public void testProcessLeader_Invalid() {
+ void testProcessLeader_Invalid() {
Leader msg = new Leader(PREV_HOST, null);
// should stay in the same state, and not start distributing
}
@Test
- public void testProcessLeader_BadLeader() {
+ void testProcessLeader_BadLeader() {
String[] arr = {HOST2, HOST1};
BucketAssignments asgn = new BucketAssignments(arr);
}
@Test
- public void testProcessLeader_GoodLeader() {
+ void testProcessLeader_GoodLeader() {
String[] arr = {HOST2, PREV_HOST, MY_HOST};
BucketAssignments asgn = new BucketAssignments(arr);
}
@Test
- public void testActiveState() {
+ void testActiveState() {
assertEquals(MY_HOST, state.getLeader());
assertEquals(ASGN3, state.getAssignments());
}
@Test
- public void testDetmNeighbors() {
+ void testDetmNeighbors() {
// if only one host (i.e., itself)
mgr.startDistributing(new BucketAssignments(new String[] {MY_HOST, MY_HOST}));
state = new ActiveState(mgr);
- assertEquals(null, state.getSuccHost());
+ assertNull(state.getSuccHost());
assertEquals("", state.getPredHost());
// two hosts
}
@Test
- public void testAddTimers_WithPredecessor() {
+ void testAddTimers_WithPredecessor() {
// invoke start() to add the timers
state.start();
}
@Test
- public void testAddTimers_SansPredecessor() {
+ void testAddTimers_SansPredecessor() {
// only one host, thus no predecessor
mgr.startDistributing(new BucketAssignments(new String[] {MY_HOST, MY_HOST}));
state = new ActiveState(mgr);
}
@Test
- public void testAddTimers_HeartbeatGenerator() {
+ void testAddTimers_HeartbeatGenerator() {
// only one host so we only have to look at one heart beat at a time
mgr.startDistributing(new BucketAssignments(new String[] {MY_HOST}));
state = new ActiveState(mgr);
}
@Test
- public void testAddTimers_MyHeartbeatSeen() {
+ void testAddTimers_MyHeartbeatSeen() {
// invoke start() to add the timers
state.start();
}
@Test
- public void testAddTimers_MyHeartbeatMissed() {
+ void testAddTimers_MyHeartbeatMissed() {
// invoke start() to add the timers
state.start();
}
@Test
- public void testAddTimers_PredecessorHeartbeatSeen() {
+ void testAddTimers_PredecessorHeartbeatSeen() {
// invoke start() to add the timers
state.start();
}
@Test
- public void testAddTimers_PredecessorHeartbeatMissed() {
+ void testAddTimers_PredecessorHeartbeatMissed() {
// invoke start() to add the timers
state.start();
}
@Test
- public void testGenHeartbeat_OneHost() {
+ void testGenHeartbeat_OneHost() {
// only one host (i.e., itself)
mgr.startDistributing(new BucketAssignments(new String[] {MY_HOST}));
state = new ActiveState(mgr);
}
@Test
- public void testGenHeartbeat_MultipleHosts() {
+ void testGenHeartbeat_MultipleHosts() {
state.start();
verify(mgr, times(2)).publish(any(), any());