From a0fd5c0d990b32027623b989d4cdd5c2be29b6f2 Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Wed, 23 Aug 2023 15:03:04 -0700 Subject: [PATCH 1/2] Refresh plugin for August 2023 --- .mvn/extensions.xml | 2 +- Jenkinsfile | 5 +- pom.xml | 64 +- .../amazon/jenkins/ec2fleet/CloudNanny.java | 4 +- .../ec2fleet/EC2FleetStatusWidgetUpdater.java | 7 +- .../jenkins/ec2fleet/aws/RegionInfo.java | 18 +- .../jenkins/ec2fleet/CloudNannyTest.java | 45 +- ...FleetAutoResubmitComputerLauncherTest.java | 55 +- .../jenkins/ec2fleet/EC2FleetCloudTest.java | 231 +++---- .../ec2fleet/EC2FleetNodeComputerTest.java | 29 +- .../ec2fleet/EC2FleetOnlineCheckerTest.java | 34 +- .../EC2FleetStatusWidgetUpdaterTest.java | 34 +- .../ec2fleet/EC2RetentionStrategyTest.java | 16 +- .../jenkins/ec2fleet/EmptyAmazonEC2.java | 605 ++++++++++++++++++ .../jenkins/ec2fleet/IntegrationTest.java | 4 +- .../NoDelayProvisionStrategyTest.java | 10 +- .../ec2fleet/ProvisionIntegrationTest.java | 4 +- .../jenkins/ec2fleet/UiIntegrationTest.java | 10 +- .../jenkins/ec2fleet/aws/EC2ApiTest.java | 6 +- .../fleet/AutoScalingGroupFleetTest.java | 294 ++++----- 20 files changed, 1077 insertions(+), 400 deletions(-) diff --git a/.mvn/extensions.xml b/.mvn/extensions.xml index 43d62816..1f363640 100644 --- a/.mvn/extensions.xml +++ b/.mvn/extensions.xml @@ -2,6 +2,6 @@ io.jenkins.tools.incrementals git-changelist-maven-extension - 1.2 + 1.7 diff --git a/Jenkinsfile b/Jenkinsfile index 804ca06d..60404f5f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,2 +1,5 @@ // https://github.com/jenkins-infra/pipeline-library -buildPlugin(failFast: false) +buildPlugin(useContainerAgent: true, configurations: [ + [platform: 'linux', jdk: 21], + [platform: 'linux', jdk: 17], +]) diff --git a/pom.xml b/pom.xml index 6eee3cad..c7098457 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.jenkins-ci.plugins plugin - 4.31 + 4.72 @@ -17,13 +17,10 @@ 2.7.2 -SNAPSHOT - 2.277.2 - 8 + 2.387.3 jenkinsci/${project.artifactId}-plugin - 1.12.101-300.vc09c7be9cb57 - 1.32 - 3.12.4 - 2.0.5 + 1.12.529-406.vdeff15e5817d + 191.vcb_f183ce58b_9 EC2 Fleet Jenkins Plugin @@ -60,8 +57,8 @@ - scm:git:https://github.com/${gitHubRepo} - scm:git:https://github.com/${gitHubRepo} + scm:git:https://github.com/${gitHubRepo}.git + scm:git:git@github.com:${gitHubRepo}.git https://github.com/${gitHubRepo} ${scmTag} @@ -84,8 +81,8 @@ io.jenkins.tools.bom - bom-2.249.x - 984.vb5eaac999a7e + bom-2.387.x + 2357.v1043f8578392 import pom @@ -118,15 +115,8 @@ - org.powermock - powermock-module-junit4 - ${powermock.version} - test - - - org.powermock - powermock-api-mockito2 - ${powermock.version} + org.mockito + mockito-core test @@ -138,17 +128,6 @@ io.jenkins.configuration-as-code test-harness test - - - - joda-time - joda-time - - @@ -161,10 +140,31 @@ true 1.45 - 8 + + + jdk17 + + [17,) + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + -Xms768M -Xmx768M -XX:+HeapDumpOnOutOfMemoryError -XX:+TieredCompilation -XX:TieredStopAtLevel=1 @{jenkins.addOpens} @{jenkins.insaneHook} --add-opens java.base/java.util.concurrent=ALL-UNNAMED --add-opens java.base/java.util.concurrent.locks=ALL-UNNAMED + + + + + + + diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/CloudNanny.java b/src/main/java/com/amazon/jenkins/ec2fleet/CloudNanny.java index 4af14599..c70170d7 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/CloudNanny.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/CloudNanny.java @@ -1,5 +1,6 @@ package com.amazon.jenkins.ec2fleet; +import com.google.common.annotations.VisibleForTesting; import hudson.Extension; import hudson.model.PeriodicWork; import hudson.slaves.Cloud; @@ -66,7 +67,8 @@ protected void doRun() { * * @return basic java list */ - private static List getClouds() { + @VisibleForTesting + static List getClouds() { return Jenkins.get().clouds; } diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdater.java b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdater.java index 75c863a8..cfef4e9e 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdater.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdater.java @@ -1,5 +1,6 @@ package com.amazon.jenkins.ec2fleet; +import com.google.common.annotations.VisibleForTesting; import hudson.Extension; import hudson.model.PeriodicWork; import hudson.slaves.Cloud; @@ -53,7 +54,8 @@ protected void doRun() { * * @return widgets */ - private static List getWidgets() { + @VisibleForTesting + static List getWidgets() { return Jenkins.get().getWidgets(); } @@ -63,7 +65,8 @@ private static List getWidgets() { * * @return basic java list */ - private static List getClouds() { + @VisibleForTesting + static List getClouds() { return Jenkins.get().clouds; } diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/aws/RegionInfo.java b/src/main/java/com/amazon/jenkins/ec2fleet/aws/RegionInfo.java index 04ee58cb..a6508c6d 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/aws/RegionInfo.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/aws/RegionInfo.java @@ -13,28 +13,36 @@ public enum RegionInfo { US_EAST_2("us-east-2", "US East (Ohio)"), US_WEST_1("us-west-1", "US West (N. California)"), US_WEST_2("us-west-2", "US West (Oregon)"), - US_ISO_EAST_1("us-iso-east-1", "US ISO East"), - US_ISOB_EAST_1("us-isob-east-1", "US ISOB East (Ohio)"), - US_ISO_WEST_1("us-iso-west-1", "US ISO West"), EU_WEST_1("eu-west-1", "EU (Ireland)"), EU_WEST_2("eu-west-2", "EU (London)"), EU_WEST_3("eu-west-3", "EU (Paris)"), EU_CENTRAL_1("eu-central-1", "EU (Frankfurt)"), + EU_CENTRAL_2("eu-central-2", "EU (Zurich)"), EU_NORTH_1("eu-north-1", "EU (Stockholm)"), EU_SOUTH_1("eu-south-1", "EU (Milan)"), - AF_SOUTH_1("af-south-1", "Africa (Cape Town)"), + EU_SOUTH_2("eu-south-2", "EU (Spain)"), AP_EAST_1("ap-east-1", "Asia Pacific (Hong Kong)"), AP_SOUTH_1("ap-south-1", "Asia Pacific (Mumbai)"), + AP_SOUTH_2("ap-south-2", "Asia Pacific (Hyderabad)"), AP_SOUTHEAST_1("ap-southeast-1", "Asia Pacific (Singapore)"), AP_SOUTHEAST_2("ap-southeast-2", "Asia Pacific (Sydney)"), + AP_SOUTHEAST_3("ap-southeast-3", "Asia Pacific (Jakarta)"), + AP_SOUTHEAST_4("ap-southeast-4", "Asia Pacific (Melbourne)"), AP_NORTHEAST_1("ap-northeast-1", "Asia Pacific (Tokyo)"), AP_NORTHEAST_2("ap-northeast-2", "Asia Pacific (Seoul)"), + AP_NORTHEAST_3("ap-northeast-3", "Asia Pacific (Osaka)"), + SA_EAST_1("sa-east-1", "South America (Sao Paulo)"), CN_NORTH_1("cn-north-1", "China (Beijing)"), CN_NORTHWEST_1("cn-northwest-1", "China (Ningxia)"), CA_CENTRAL_1("ca-central-1", "Canada (Central)"), + ME_CENTRAL_1("me-central-1", "Middle East (UAE)"), ME_SOUTH_1("me-south-1", "Middle East (Bahrain)"), - AP_NORTHEAST_3("ap-northeast-3", "Asia Pacific (Osaka)"); + AF_SOUTH_1("af-south-1", "Africa (Cape Town)"), + US_ISO_EAST_1("us-iso-east-1", "US ISO East"), + US_ISOB_EAST_1("us-isob-east-1", "US ISOB East (Ohio)"), + US_ISO_WEST_1("us-iso-west-1", "US ISO West"), + IL_CENTRAL_1("il-central-1", "Israel (Tel Aviv)"); private final String name; private final String description; diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/CloudNannyTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/CloudNannyTest.java index fb4075cf..f4b82f61 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/CloudNannyTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/CloudNannyTest.java @@ -1,15 +1,16 @@ package com.amazon.jenkins.ec2fleet; import hudson.slaves.Cloud; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -21,18 +22,19 @@ import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; -@RunWith(PowerMockRunner.class) -@PrepareForTest(CloudNanny.class) +@RunWith(MockitoJUnitRunner.class) public class CloudNannyTest { - @Mock + private MockedStatic mockedCloudNanny; + + @Mock(strictness = Mock.Strictness.LENIENT) private EC2FleetCloud cloud1; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private EC2FleetCloud cloud2; private List clouds = new ArrayList<>(); @@ -52,8 +54,8 @@ public class CloudNannyTest { @Before public void before() throws Exception { - PowerMockito.mockStatic(CloudNanny.class); - PowerMockito.when(CloudNanny.class, "getClouds").thenReturn(clouds); + mockedCloudNanny = Mockito.mockStatic(CloudNanny.class); + mockedCloudNanny.when(CloudNanny::getClouds).thenReturn(clouds); when(cloud1.getLabelString()).thenReturn("a"); when(cloud2.getLabelString()).thenReturn(""); @@ -70,18 +72,33 @@ public void before() throws Exception { recurrenceCounters.put(cloud2, recurrenceCounter2); } + @After + public void after() { + mockedCloudNanny.close(); + } + private CloudNanny getMockCloudNannyInstance() { - CloudNanny cloudNanny = Whitebox.newInstance(CloudNanny.class); + CloudNanny cloudNanny = new CloudNanny(); // next execution should trigger running the status check. recurrenceCounter1.set(1); recurrenceCounter2.set(1); - Whitebox.setInternalState(cloudNanny, "recurrenceCounters", recurrenceCounters); + setInternalState(cloudNanny, "recurrenceCounters", recurrenceCounters); return cloudNanny; } + private static void setInternalState(Object obj, String fieldName, Object newValue) { + try { + Field field = obj.getClass().getDeclaredField(fieldName); + field.setAccessible(true); + field.set(obj, newValue); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + @Test public void shouldDoNothingIfNoCloudsAndWidgets() { getMockCloudNannyInstance().doRun(); @@ -105,7 +122,7 @@ public void shouldIgnoreNonEC2FleetClouds() { getMockCloudNannyInstance().doRun(); verify(cloud1).update(); - verifyZeroInteractions(nonEc2FleetCloud); + verifyNoInteractions(nonEc2FleetCloud); } @Test diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetAutoResubmitComputerLauncherTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetAutoResubmitComputerLauncherTest.java index 06974bf6..76f78b17 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetAutoResubmitComputerLauncherTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetAutoResubmitComputerLauncherTest.java @@ -12,13 +12,14 @@ import jenkins.model.Jenkins; import org.jenkinsci.plugins.workflow.job.WorkflowJob; import org.jenkinsci.plugins.workflow.job.WorkflowRun; +import org.junit.After; import org.junit.Before; -import org.junit.Test; import org.junit.runner.RunWith; +import org.junit.Test; import org.mockito.Mock; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; import java.util.Arrays; import java.util.Collections; @@ -29,15 +30,19 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import static org.mockito.Mockito.withSettings; @SuppressWarnings("ArraysAsListWithZeroOrOneArgument") -@RunWith(PowerMockRunner.class) -@PrepareForTest({Jenkins.class, Queue.class, WorkflowJob.class, WorkflowRun.class}) +@RunWith(MockitoJUnitRunner.class) public class EC2FleetAutoResubmitComputerLauncherTest { + private MockedStatic mockedJenkins; + + private MockedStatic mockedQueue; + @Mock private ComputerLauncher baseComputerLauncher; @@ -58,10 +63,10 @@ public class EC2FleetAutoResubmitComputerLauncherTest { @Mock private Queue.Executable executable2; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private Slave agent; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private EC2FleetNodeComputer computer; @Mock @@ -82,7 +87,7 @@ public class EC2FleetAutoResubmitComputerLauncherTest { @Mock private Queue.Task task2; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private EC2FleetNode fleetNode; @Mock @@ -100,10 +105,10 @@ public void before() { when(computer.getDisplayName()).thenReturn("i-12"); - PowerMockito.mockStatic(Jenkins.class); - PowerMockito.mockStatic(Queue.class); - when(Jenkins.get()).thenReturn(jenkins); - when(Queue.getInstance()).thenReturn(queue); + mockedJenkins = Mockito.mockStatic(Jenkins.class); + mockedJenkins.when(Jenkins::get).thenReturn(jenkins); + mockedQueue = Mockito.mockStatic(Queue.class); + mockedQueue.when(Queue::getInstance).thenReturn(queue); when(agent.getNumExecutors()).thenReturn(1); @@ -124,12 +129,18 @@ public void before() { when(computer.getCloud()).thenReturn(cloud); } + @After + public void after() { + mockedQueue.close(); + mockedJenkins.close(); + } + @Test public void afterDisconnect_should_do_nothing_if_still_online() { when(computer.isOffline()).thenReturn(false); new EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) .afterDisconnect(computer, taskListener); - verifyZeroInteractions(queue); + verifyNoInteractions(queue); } @Test @@ -138,7 +149,7 @@ public void afterDisconnect_should_do_nothing_if_offline_but_no_executable() { when(executor1.getCurrentExecutable()).thenReturn(null); new EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) .afterDisconnect(computer, taskListener); - verifyZeroInteractions(queue); + verifyNoInteractions(queue); } @Test @@ -147,7 +158,7 @@ public void taskCompleted_should_resubmit_task_if_offline_and_has_executable() { new EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) .afterDisconnect(computer, taskListener); verify(queue).schedule2(eq(task1), anyInt(), eq(Collections.emptyList())); - verifyZeroInteractions(queue); + verifyNoMoreInteractions(queue); } @Test @@ -156,7 +167,7 @@ public void taskCompleted_should_not_resubmit_task_if_offline_but_disabled() { when(computer.getExecutors()).thenReturn(Arrays.asList(executor1)); new EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) .afterDisconnect(computer, taskListener); - verifyZeroInteractions(queue); + verifyNoInteractions(queue); } @Test @@ -165,7 +176,7 @@ public void taskCompleted_should_resubmit_task_for_all_executors() { .afterDisconnect(computer, taskListener); verify(queue).schedule2(eq(task1), anyInt(), eq(Collections.emptyList())); verify(queue).schedule2(eq(task2), anyInt(), eq(Collections.emptyList())); - verifyZeroInteractions(queue); + verifyNoMoreInteractions(queue); } @Test @@ -179,11 +190,11 @@ public void taskCompleted_should_abort_executors_during_resubmit() { @Test public void taskCompleted_should_resubmit_task_with_actions() { when(computer.getExecutors()).thenReturn(Arrays.asList(executor1)); - when(executable1.getActions()).thenReturn(Arrays.asList(action1)); + //when(executable1.getActions()).thenReturn(Arrays.asList(action1)); new EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) .afterDisconnect(computer, taskListener); - verify(queue).schedule2(eq(task1), anyInt(), eq(Arrays.asList(action1))); - verifyZeroInteractions(queue); + verify(queue).schedule2(eq(task1), anyInt(), eq(/* Arrays.asList(action1) */ Collections.emptyList())); + verifyNoMoreInteractions(queue); } @Test diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudTest.java index 623582e7..33300d1b 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudTest.java @@ -40,11 +40,12 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; +import org.mockito.MockedConstruction; +import org.mockito.MockedStatic; +import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; +import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; import java.io.IOException; import java.util.ArrayList; @@ -78,11 +79,17 @@ import static org.mockito.Mockito.when; @SuppressWarnings("unchecked") -@RunWith(PowerMockRunner.class) -@PrepareForTest({Jenkins.class, EC2FleetCloud.class, EC2FleetCloud.DescriptorImpl.class, - LabelFinder.class, FleetStateStats.class, EC2Fleets.class, EC2FleetNodeComputer.class}) +@RunWith(MockitoJUnitRunner.class) public class EC2FleetCloudTest { + private MockedStatic mockedEC2Fleets; + + private MockedStatic mockedFleetStateStats; + + private MockedStatic mockedLabelFinder; + + private MockedStatic mockedJenkins; + private SpotFleetRequestConfig spotFleetRequestConfig1; private SpotFleetRequestConfig spotFleetRequestConfig2; private SpotFleetRequestConfig spotFleetRequestConfig3; @@ -92,13 +99,13 @@ public class EC2FleetCloudTest { private SpotFleetRequestConfig spotFleetRequestConfig7; private SpotFleetRequestConfig spotFleetRequestConfig8; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private Jenkins jenkins; @Mock private EC2Fleet ec2Fleet; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private EC2Api ec2Api; @Mock @@ -138,23 +145,25 @@ public void before() { spotFleetRequestConfig8.setSpotFleetRequestConfig(new SpotFleetRequestConfigData().withType(FleetType.Request)); Registry.setEc2Api(ec2Api); + mockedEC2Fleets = Mockito.mockStatic(EC2Fleets.class); + mockedEC2Fleets.when(() -> EC2Fleets.get(anyString())).thenReturn(ec2Fleet); + mockedJenkins = Mockito.mockStatic(Jenkins.class); + mockedJenkins.when(Jenkins::get).thenReturn(jenkins); - PowerMockito.mockStatic(EC2Fleets.class); - when(EC2Fleets.get(anyString())).thenReturn(ec2Fleet); - - PowerMockito.mockStatic(FleetStateStats.class); - PowerMockito.mockStatic(LabelFinder.class); + Mockito.when(idleComputer.isIdle()).thenReturn(true); + Mockito.when(busyComputer.isIdle()).thenReturn(false); - PowerMockito.mockStatic(Jenkins.class); - PowerMockito.when(Jenkins.get()).thenReturn(jenkins); - - PowerMockito.when(idleComputer.isIdle()).thenReturn(true); - PowerMockito.when(busyComputer.isIdle()).thenReturn(false); + mockedFleetStateStats = Mockito.mockStatic(FleetStateStats.class); + mockedLabelFinder = Mockito.mockStatic(LabelFinder.class); } @After public void after() { Registry.setEc2Api(new EC2Api()); + mockedJenkins.close(); + mockedLabelFinder.close(); + mockedFleetStateStats.close(); + mockedEC2Fleets.close(); } @Test @@ -218,7 +227,7 @@ public void provision_shouldProvisionNoneWhenMaxReached() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); @@ -244,7 +253,7 @@ public void provision_shouldProvisionNoneWhenMaxReachedAndNumExecutorsMoreOne() // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); @@ -270,7 +279,7 @@ public void provision_shouldProvisionNoneWhenMaxReachedAndNumExecutorsMoreOne1() // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); @@ -296,7 +305,7 @@ public void provision_shouldProvisionNoneWhenExceedMax() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); @@ -322,7 +331,7 @@ public void provision_shouldProvisionIfBelowMax() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); @@ -348,7 +357,7 @@ public void provision_shouldProvisionNoMoreMax() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); @@ -374,7 +383,7 @@ public void provision_shouldProvisionNoMoreMaxWhenMultipleCallBeforeUpdate() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); @@ -405,7 +414,7 @@ public void provision_shouldProvisionNoneIfNotYetUpdated() { when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); // Don't set the status - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(null); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", @@ -428,7 +437,7 @@ public void scheduleToTerminate_shouldNotRemoveIfStatsNotUpdated() { when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); // Don't set the status - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(null); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", @@ -449,7 +458,7 @@ public void scheduleToTerminate_notRemoveIfBelowMin() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); @@ -474,7 +483,7 @@ public void scheduleToTerminate_notRemoveIfEqualMin() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); @@ -499,7 +508,7 @@ public void scheduleToTerminate_notRemoveIfEqualMinSpare() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); when(jenkins.getComputers()).thenReturn(new Computer[0]); @@ -525,7 +534,7 @@ public void scheduleToTerminate_remove() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); @@ -551,7 +560,7 @@ public void scheduleToTerminate_upToZeroNodes() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); @@ -582,7 +591,7 @@ public void scheduleToTerminate_removeNoMoreMinIfCalledMultipleBeforeUpdate() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); @@ -615,7 +624,7 @@ public void update_shouldDoNothingIfNoTerminationOrProvisionAndFleetIsEmpty() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); @@ -639,7 +648,7 @@ public void update_shouldIncreaseTargetCapacityWhenProvisioned() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); @@ -668,7 +677,7 @@ public void update_shouldResetTerminateAndProvision() { final FleetStateStats currentState = new FleetStateStats("fleetId", 5, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap()); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(currentState); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", @@ -696,7 +705,7 @@ public void update_shouldNotIncreaseMoreThenMax() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); @@ -727,7 +736,7 @@ public void update_shouldNotCountScheduledToTerminateWhenScaleUp() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 5, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); @@ -757,7 +766,7 @@ public void update_shouldDecreaseTargetCapacityAndTerminateInstancesIfScheduled( // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 4, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); @@ -796,14 +805,14 @@ public void update_shouldAddNodeIfAnyNewDescribed() throws IOException { when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap())); mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, false, "-1", false, 0, 0, false, 10, false); @@ -838,14 +847,14 @@ public void update_shouldTagNewNodesBeforeAdding() throws IOException { when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), new HashSet<>(Arrays.asList("i-0", "i-1")), Collections.emptyMap())); mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 2, 0, 1, false, false, "-1", false, 0, 0, false, 10, false); @@ -874,14 +883,14 @@ public void update_shouldTagNewNodesBeforeAddingWithFleetName() throws IOExcepti when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap())); mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud("my-fleet", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, false, "-1", false, 0, 0, false, 10, false); @@ -915,14 +924,14 @@ public void update_givenFailedTaggingShouldIgnoreExceptionAndAddNode() throws IO when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap())); mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, false, "-1", false, 0, 0, false, 10, false); @@ -944,7 +953,7 @@ public void update_shouldAddNodeIfAnyNewDescribed_restrictUsage() throws IOExcep // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap())); @@ -960,7 +969,7 @@ public void update_shouldAddNodeIfAnyNewDescribed_restrictUsage() throws IOExcep mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, 0, 0, false, 10, false); @@ -997,7 +1006,7 @@ public void update_shouldAddNodeWithNumExecutors_whenWeightProvidedButNotEnabled when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.singletonMap(instanceType, 1.1))); @@ -1005,7 +1014,7 @@ public void update_shouldAddNodeWithNumExecutors_whenWeightProvidedButNotEnabled mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, 0, 0, false, 10, false); @@ -1032,13 +1041,13 @@ public void update_givenManuallyUpdatedFleetShouldCorrectLocalTargetCapacityToKe final FleetStateStats initState = new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), new HashSet<>(Arrays.asList("i-0", "i-1")), Collections.emptyMap()); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(initState); mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 10, 0, 1, false, true, "-1", false, 0, 0, false, 10, false); @@ -1069,13 +1078,13 @@ public void update_shouldTrimPlannedNodesIfExceedTargetCapacity() throws IOExcep final FleetStateStats initState = new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap()); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(initState); mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 10, 0, 1, false, true, "-1", false, 0, 0, false, 10, false); @@ -1123,7 +1132,7 @@ public void update_shouldTrimPlannedNodesBasedOnUpdatedTargetCapacityIfProvision mockNodeCreatingPart(); final EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 10, 0, 1, false, true, "-1", false, 0, 0, false, 10, false); @@ -1169,13 +1178,13 @@ public void update_shouldUpdateStateWithFleetTargetCapacityPlusToAdd() throws IO final FleetStateStats initState = new FleetStateStats("fleetId", 5, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap()); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(initState); mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 10, 0,1, false, true, "-1", false, 0, 0, false, 10, false); @@ -1215,13 +1224,13 @@ public void update_shouldUpdateStateWithFleetTargetCapacityMinusToTerminate() th final FleetStateStats initState = new FleetStateStats("fleetId", 5, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap()); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(initState); mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 10,0, 1, false, true, "-1", false, 0, 0, false, 10, false); @@ -1250,13 +1259,13 @@ public void update_shouldTerminateIdleOrNullInstancesOnly() { put("i-2", new Instance().withPublicIpAddress("p-ip").withInstanceId("i-2")); put("i-3", new Instance().withPublicIpAddress("p-ip").withInstanceId("i-3")); }}); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), new HashSet<>(Arrays.asList("i-1", "i-2", "i-3")), Collections.emptyMap())); mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 2, 0, 1, false, false, "-1", false, 0, 0, false, 10, false); @@ -1296,11 +1305,11 @@ public void update_shouldUpdateStateWithMinSpare() throws IOException { final FleetStateStats initState = new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap()); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(initState); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 10, minSpareSize, 1, false, true, "-1", false, 0, 0, false, 10, false); @@ -1333,7 +1342,7 @@ public void update_shouldAddNodeWithScaledNumExecutors_whenWeightPresentAndEnabl when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton(instanceId), Collections.singletonMap(instanceType, 2.0))); @@ -1341,7 +1350,7 @@ public void update_shouldAddNodeWithScaledNumExecutors_whenWeightPresentAndEnabl mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, 0, 0, true, 10, false); @@ -1375,7 +1384,7 @@ public void update_shouldAddNodeWithNumExecutors_whenWeightPresentAndEnabledButF when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton(instanceId), Collections.singletonMap("diff-t", 2.0))); @@ -1383,7 +1392,7 @@ public void update_shouldAddNodeWithNumExecutors_whenWeightPresentAndEnabledButF mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, 0, 0, true, 10, false); @@ -1417,7 +1426,7 @@ public void update_shouldAddNodeWithRoundToLowScaledNumExecutors_whenWeightPrese when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton(instanceId), Collections.singletonMap(instanceType, 1.44))); @@ -1425,7 +1434,7 @@ public void update_shouldAddNodeWithRoundToLowScaledNumExecutors_whenWeightPrese mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, 0, 0, true, 10, false); @@ -1459,7 +1468,7 @@ public void update_shouldAddNodeWithRoundToLowScaledNumExecutors_whenWeightPrese when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton(instanceId), Collections.singletonMap(instanceType, 1.5))); @@ -1467,7 +1476,7 @@ public void update_shouldAddNodeWithRoundToLowScaledNumExecutors_whenWeightPrese mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, 0, 0, true, 10, false); @@ -1501,16 +1510,16 @@ public void update_shouldAddNodeWithScaledToOneNumExecutors_whenWeightPresentBut when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton(instanceId), Collections.emptyMap())); - PowerMockito.doThrow(new UnsupportedOperationException("Test exception")).when(ec2Fleet) + Mockito.doThrow(new UnsupportedOperationException("Test exception")).when(ec2Fleet) .modify(anyString(), anyString(), anyString(), anyString(), anyInt(), anyInt(), anyInt()); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, 0, 0, true, 10, false); @@ -1547,7 +1556,7 @@ public void update_givenFailedModifyShouldNotUpdateToAddToDelete() throws IOExce when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton(instanceId), Collections.singletonMap(instanceType, .1))); @@ -1555,7 +1564,7 @@ public void update_givenFailedModifyShouldNotUpdateToAddToDelete() throws IOExce mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, 0, 0, true, 10, false); @@ -1593,7 +1602,7 @@ public void update_givenFleetInModifyingShouldNotDoAnyUpdates() throws IOExcepti FleetStateStats.State.modifying(""), Collections.singleton(instanceId), Collections.singletonMap(instanceType, .1)); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn(stats); + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn(stats); final FleetStateStats initialState = new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), @@ -1603,7 +1612,7 @@ public void update_givenFleetInModifyingShouldNotDoAnyUpdates() throws IOExcepti mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, 0, 0, true, 10, false); @@ -1626,7 +1635,7 @@ public void update_scheduledFuturesExecutesAfterTimeout() throws IOException, In // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); @@ -1657,7 +1666,7 @@ public void update_scheduledFuturesIsCancelledAfterUpdate() throws IOException, // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); @@ -1686,12 +1695,12 @@ public void update_scheduledFuturesIsCancelledAfterUpdate() throws IOException, @Test public void update_shouldScaleUpToMinSize() { // given - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + Mockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 1, 1, 0,1, false, true, "-1", false, 0, 0, true, 10, false); @@ -1707,7 +1716,7 @@ public void update_shouldScaleUpToMinSize() { public void removeScheduledFutures_success() { // given EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, 0, 0, true, 10, false); @@ -1728,7 +1737,7 @@ public void removeScheduledFutures_success() { public void removeScheduledFutures_scheduledFutureIsEmpty() { // given EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, 0, 0, true, 10, false); @@ -1747,7 +1756,7 @@ public void removeScheduledFutures_scheduledFutureIsEmpty() { public void removeScheduledFutures_numToRemoveIsZero() { // given EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", - "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, + "", "fleetId", "", null, Mockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, 0, 0, true, 10, false); @@ -1779,40 +1788,40 @@ public void descriptorImpl_doFillRegionItems_returnStaticRegionsIfApiCallFailed( @Test public void descriptorImpl_doTestConnection_NoMissingPermissions() throws Exception { - final AwsPermissionChecker awsPermissionChecker = mock(AwsPermissionChecker.class); - when(awsPermissionChecker.getMissingPermissions(null)).thenReturn(new ArrayList<>()); - PowerMockito.whenNew(AwsPermissionChecker.class).withAnyArguments().thenReturn(awsPermissionChecker); - - final FormValidation formValidation = new EC2FleetCloud.DescriptorImpl().doTestConnection("credentials", null, null, null); + try (MockedConstruction mockedAwsPermissionChecker = Mockito.mockConstruction(AwsPermissionChecker.class, (awsPermissionChecker, context) -> { + when(awsPermissionChecker.getMissingPermissions(null)).thenReturn(new ArrayList<>()); + })) { + final FormValidation formValidation = new EC2FleetCloud.DescriptorImpl().doTestConnection("credentials", null, null, null); - Assert.assertTrue(formValidation.getMessage().contains("Success")); + Assert.assertTrue(formValidation.getMessage().contains("Success")); + } } @Test public void descriptorImpl_doTestConnection_missingDescribeInstancePermission() throws Exception { - final AwsPermissionChecker awsPermissionChecker = mock(AwsPermissionChecker.class); - when(awsPermissionChecker.getMissingPermissions(null)).thenReturn(Collections.singletonList(AwsPermissionChecker.FleetAPI.DescribeInstances.name())); - PowerMockito.whenNew(AwsPermissionChecker.class).withAnyArguments().thenReturn(awsPermissionChecker); - - final FormValidation formValidation = new EC2FleetCloud.DescriptorImpl().doTestConnection("credentials", null, null, null); + try (MockedConstruction mockedAwsPermissionChecker = Mockito.mockConstruction(AwsPermissionChecker.class, (awsPermissionChecker, context) -> { + when(awsPermissionChecker.getMissingPermissions(null)).thenReturn(Collections.singletonList(AwsPermissionChecker.FleetAPI.DescribeInstances.name())); + })) { + final FormValidation formValidation = new EC2FleetCloud.DescriptorImpl().doTestConnection("credentials", null, null, null); - Assert.assertThat(formValidation.getMessage(), Matchers.containsString(AwsPermissionChecker.FleetAPI.DescribeInstances.name())); + Assert.assertThat(formValidation.getMessage(), Matchers.containsString(AwsPermissionChecker.FleetAPI.DescribeInstances.name())); + } } @Test public void descriptorImpl_doTestConnection_missingMultiplePermissions() throws Exception { - final List missingPermissions = new ArrayList<>(); - missingPermissions.add(AwsPermissionChecker.FleetAPI.DescribeInstances.name()); - missingPermissions.add(AwsPermissionChecker.FleetAPI.CreateTags.name()); - - final AwsPermissionChecker awsPermissionChecker = mock(AwsPermissionChecker.class); - when(awsPermissionChecker.getMissingPermissions(null)).thenReturn(missingPermissions); - PowerMockito.whenNew(AwsPermissionChecker.class).withAnyArguments().thenReturn(awsPermissionChecker); + try (MockedConstruction mockedAwsPermissionChecker = Mockito.mockConstruction(AwsPermissionChecker.class, (awsPermissionChecker, context) -> { + final List missingPermissions = new ArrayList<>(); + missingPermissions.add(AwsPermissionChecker.FleetAPI.DescribeInstances.name()); + missingPermissions.add(AwsPermissionChecker.FleetAPI.CreateTags.name()); - final FormValidation formValidation = new EC2FleetCloud.DescriptorImpl().doTestConnection("credentials", null, null, null); + when(awsPermissionChecker.getMissingPermissions(null)).thenReturn(missingPermissions); + })) { + final FormValidation formValidation = new EC2FleetCloud.DescriptorImpl().doTestConnection("credentials", null, null, null); - Assert.assertThat(formValidation.getMessage(), Matchers.containsString(AwsPermissionChecker.FleetAPI.DescribeInstances.name())); - Assert.assertThat(formValidation.getMessage(), Matchers.containsString(AwsPermissionChecker.FleetAPI.CreateTags.name())); + Assert.assertThat(formValidation.getMessage(), Matchers.containsString(AwsPermissionChecker.FleetAPI.DescribeInstances.name())); + Assert.assertThat(formValidation.getMessage(), Matchers.containsString(AwsPermissionChecker.FleetAPI.CreateTags.name())); + } } @Test @@ -1913,7 +1922,7 @@ public void descriptorImpl_doFillFleetItems_returnEmptyListIfNoEmptyEC2Fleet() { public void descriptorImpl_doFillFleetItems_returnFleetsProvidedByAllEC2Fleets() { final EC2Fleet ec2SpotFleet = mock(EC2SpotFleet.class); final EC2Fleet autoScalingGroupFleet = mock(AutoScalingGroupFleet.class); - when(EC2Fleets.all()).thenReturn(Arrays.asList(ec2SpotFleet, autoScalingGroupFleet)); + mockedEC2Fleets.when(EC2Fleets::all).thenReturn(Arrays.asList(ec2SpotFleet, autoScalingGroupFleet)); ListBoxModel r = new EC2FleetCloud.DescriptorImpl().doFillFleetItems( false, "", "", "", ""); @@ -1931,7 +1940,7 @@ public void descriptorImpl_doFillFleetItems_returnEmptyListIfAnyException() { anyString(), anyString(), anyString(), any(ListBoxModel.class), anyString(), anyBoolean()); final EC2Fleet autoScalingGroupFleet = mock(AutoScalingGroupFleet.class); - when(EC2Fleets.all()).thenReturn(Arrays.asList(ec2SpotFleet, autoScalingGroupFleet)); + mockedEC2Fleets.when(EC2Fleets::all).thenReturn(Arrays.asList(ec2SpotFleet, autoScalingGroupFleet)); ListBoxModel r = new EC2FleetCloud.DescriptorImpl().doFillFleetItems( false, "", "", "", ""); @@ -2096,7 +2105,7 @@ private void mockNodeCreatingPart() { ExtensionList labelFinder = mock(ExtensionList.class); when(labelFinder.iterator()).thenReturn(Collections.emptyIterator()); - PowerMockito.when(LabelFinder.all()).thenReturn(labelFinder); + mockedLabelFinder.when(LabelFinder::all).thenReturn(labelFinder); // mocking part of node creation process Jenkins.get().getLabelAtom(l) when(jenkins.getLabelAtom(anyString())).thenReturn(new LabelAtom("mock-label")); diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetNodeComputerTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetNodeComputerTest.java index 684aaafc..1398aba8 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetNodeComputerTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetNodeComputerTest.java @@ -2,23 +2,27 @@ import hudson.model.Queue; import jenkins.model.Jenkins; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; -@RunWith(PowerMockRunner.class) -@PrepareForTest({Jenkins.class, Queue.class}) +@RunWith(MockitoJUnitRunner.class) public class EC2FleetNodeComputerTest { + private MockedStatic mockedJenkins; + + private MockedStatic mockedQueue; + @Mock private EC2FleetNode agent; @@ -30,14 +34,21 @@ public class EC2FleetNodeComputerTest { @Before public void before() { - PowerMockito.mockStatic(Jenkins.class); - PowerMockito.mockStatic(Queue.class); - when(Jenkins.get()).thenReturn(jenkins); - when(Queue.getInstance()).thenReturn(queue); + mockedJenkins = Mockito.mockStatic(Jenkins.class); + mockedJenkins.when(Jenkins::get).thenReturn(jenkins); + + mockedQueue = Mockito.mockStatic(Queue.class); + mockedQueue.when(Queue::getInstance).thenReturn(queue); when(agent.getNumExecutors()).thenReturn(1); } + @After + public void after() { + mockedQueue.close(); + mockedJenkins.close(); + } + @Test public void getDisplayName_returns_node_display_name_for_default_maxTotalUses() { when(agent.getDisplayName()).thenReturn("a n"); diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetOnlineCheckerTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetOnlineCheckerTest.java index 25f3691e..26a1682e 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetOnlineCheckerTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetOnlineCheckerTest.java @@ -3,14 +3,15 @@ import hudson.model.Computer; import hudson.model.Node; import jenkins.model.Jenkins; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; import java.util.concurrent.CancellationException; import java.util.concurrent.CompletableFuture; @@ -24,16 +25,17 @@ import static org.mockito.Mockito.when; -@RunWith(PowerMockRunner.class) -@PrepareForTest({EC2FleetOnlineChecker.class, EC2FleetNode.class, Jenkins.class, Computer.class}) +@RunWith(MockitoJUnitRunner.class) public class EC2FleetOnlineCheckerTest { + private MockedStatic mockedJenkins; + private CompletableFuture future = new CompletableFuture<>(); @Mock private EC2FleetNode node; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private Computer computer; @Mock @@ -43,14 +45,16 @@ public class EC2FleetOnlineCheckerTest { public void before() throws Exception { when(node.getDisplayName()).thenReturn("MockEC2FleetCloud i-1"); - PowerMockito.mockStatic(Jenkins.class); - - when(Jenkins.get()).thenReturn(jenkins); + mockedJenkins = Mockito.mockStatic(Jenkins.class); + mockedJenkins.when(Jenkins::get).thenReturn(jenkins); // final method - PowerMockito.when(node.toComputer()).thenReturn(computer); + Mockito.when(node.toComputer()).thenReturn(computer); + } - PowerMockito.whenNew(EC2FleetNode.class).withAnyArguments().thenReturn(node); + @After + public void after() { + mockedJenkins.close(); } @Test @@ -81,7 +85,7 @@ public void shouldStopAndFailFutureIfTimeout() { @Test public void shouldFinishWithNodeWhenSuccessfulConnect() throws InterruptedException, ExecutionException { - PowerMockito.when(computer.isOnline()).thenReturn(true); + Mockito.when(computer.isOnline()).thenReturn(true); EC2FleetOnlineChecker.start(node, future, TimeUnit.MINUTES.toMillis(1), 0); @@ -106,7 +110,7 @@ public void shouldSuccessfullyFinishAndNoWaitIfIntervalIsZero() throws Execution @Test public void shouldWaitIfOffline() throws InterruptedException, ExecutionException { - PowerMockito.when(computer.isOnline()) + Mockito.when(computer.isOnline()) .thenReturn(false) .thenReturn(false) .thenReturn(false) @@ -120,9 +124,9 @@ public void shouldWaitIfOffline() throws InterruptedException, ExecutionExceptio @Test public void shouldWaitIfComputerIsNull() throws InterruptedException, ExecutionException { - PowerMockito.when(computer.isOnline()).thenReturn(true); + Mockito.when(computer.isOnline()).thenReturn(true); - PowerMockito.when(node.toComputer()) + Mockito.when(node.toComputer()) .thenReturn(null) .thenReturn(null) .thenReturn(computer); diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdaterTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdaterTest.java index 73980aaa..d98520f2 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdaterTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdaterTest.java @@ -2,14 +2,14 @@ import hudson.slaves.Cloud; import hudson.widgets.Widget; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; import java.util.Arrays; @@ -19,13 +19,14 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -@RunWith(PowerMockRunner.class) -@PrepareForTest(EC2FleetStatusWidgetUpdater.class) +@RunWith(MockitoJUnitRunner.class) public class EC2FleetStatusWidgetUpdaterTest { + private MockedStatic mockedEC2FleetStatusWidgetUpdater; + @Mock private EC2FleetCloud cloud1; @@ -50,9 +51,9 @@ public class EC2FleetStatusWidgetUpdaterTest { @Before public void before() throws Exception { - PowerMockito.mockStatic(EC2FleetStatusWidgetUpdater.class); - PowerMockito.when(EC2FleetStatusWidgetUpdater.class, "getClouds").thenReturn(clouds); - PowerMockito.when(EC2FleetStatusWidgetUpdater.class, "getWidgets").thenReturn(widgets); + mockedEC2FleetStatusWidgetUpdater = Mockito.mockStatic(EC2FleetStatusWidgetUpdater.class); + mockedEC2FleetStatusWidgetUpdater.when(EC2FleetStatusWidgetUpdater::getClouds).thenReturn(clouds); + mockedEC2FleetStatusWidgetUpdater.when(EC2FleetStatusWidgetUpdater::getWidgets).thenReturn(widgets); when(cloud1.getLabelString()).thenReturn("a"); when(cloud2.getLabelString()).thenReturn(""); @@ -64,7 +65,12 @@ public void before() throws Exception { } private EC2FleetStatusWidgetUpdater getMockEC2FleetStatusWidgetUpdater() { - return Whitebox.newInstance(EC2FleetStatusWidgetUpdater.class); + return new EC2FleetStatusWidgetUpdater(); + } + + @After + public void after() { + mockedEC2FleetStatusWidgetUpdater.close(); } @Test @@ -79,7 +85,7 @@ public void shouldDoNothingIfNoWidgets() { getMockEC2FleetStatusWidgetUpdater().doRun(); - verifyZeroInteractions(widget1, widget2); + verifyNoInteractions(widget1, widget2); } @Test @@ -94,7 +100,7 @@ public void shouldIgnoreNonEC2FleetClouds() { getMockEC2FleetStatusWidgetUpdater().doRun(); verify(cloud1).getStats(); - verifyZeroInteractions(nonEc2FleetCloud); + verifyNoInteractions(nonEc2FleetCloud); } @Test @@ -125,7 +131,7 @@ public void shouldIgnoreNonEc2FleetWidgets() { getMockEC2FleetStatusWidgetUpdater().doRun(); verify(widget1).setStatusList(any(List.class)); - verifyZeroInteractions(nonEc2FleetWidget); + verifyNoInteractions(nonEc2FleetWidget); } } diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategyTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategyTest.java index 24e3b408..025b0536 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategyTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategyTest.java @@ -8,9 +8,8 @@ import org.junit.runner.RunWith; import org.mockito.InOrder; import org.mockito.Mock; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; import java.util.concurrent.TimeUnit; @@ -26,14 +25,13 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -@RunWith(PowerMockRunner.class) -@PrepareForTest(SlaveComputer.class) +@RunWith(MockitoJUnitRunner.class) public class EC2RetentionStrategyTest { - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private EC2FleetCloud cloud; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private EC2FleetNodeComputer computer; @Mock @@ -51,9 +49,9 @@ public void before() { when(cloud.hasUnlimitedUsesForNodes()).thenReturn(true); when(cloud.isAlwaysReconnect()).thenReturn(false); - PowerMockito.when(computer.getIdleStartMilliseconds()).thenReturn(System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(11)); + Mockito.when(computer.getIdleStartMilliseconds()).thenReturn(System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(11)); when(computer.getNode()).thenReturn(node); - PowerMockito.when(computer.isIdle()).thenReturn(true); + Mockito.when(computer.isIdle()).thenReturn(true); when(computer.isAcceptingTasks()).thenReturn(true); when(computer.getCloud()).thenReturn(cloud); when(computer.isMarkedForDeletion()).thenReturn(false); diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/EmptyAmazonEC2.java b/src/test/java/com/amazon/jenkins/ec2fleet/EmptyAmazonEC2.java index 8c01bc86..798655c2 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/EmptyAmazonEC2.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/EmptyAmazonEC2.java @@ -20,6 +20,11 @@ public void setRegion(Region region) { } + @Override + public AcceptAddressTransferResult acceptAddressTransfer(AcceptAddressTransferRequest acceptAddressTransferRequest) { + return null; + } + @Override public AcceptReservedInstancesExchangeQuoteResult acceptReservedInstancesExchangeQuote(AcceptReservedInstancesExchangeQuoteRequest acceptReservedInstancesExchangeQuoteRequest) { return null; @@ -75,6 +80,11 @@ public AllocateHostsResult allocateHosts(AllocateHostsRequest allocateHostsReque return null; } + @Override + public AllocateIpamPoolCidrResult allocateIpamPoolCidr(AllocateIpamPoolCidrRequest allocateIpamPoolCidrRequest) { + return null; + } + @Override public ApplySecurityGroupsToClientVpnTargetNetworkResult applySecurityGroupsToClientVpnTargetNetwork(ApplySecurityGroupsToClientVpnTargetNetworkRequest applySecurityGroupsToClientVpnTargetNetworkRequest) { return null; @@ -90,6 +100,11 @@ public AssignPrivateIpAddressesResult assignPrivateIpAddresses(AssignPrivateIpAd return null; } + @Override + public AssignPrivateNatGatewayAddressResult assignPrivateNatGatewayAddress(AssignPrivateNatGatewayAddressRequest assignPrivateNatGatewayAddressRequest) { + return null; + } + @Override public AssociateAddressResult associateAddress(AssociateAddressRequest associateAddressRequest) { return null; @@ -120,6 +135,16 @@ public AssociateInstanceEventWindowResult associateInstanceEventWindow(Associate return null; } + @Override + public AssociateIpamResourceDiscoveryResult associateIpamResourceDiscovery(AssociateIpamResourceDiscoveryRequest associateIpamResourceDiscoveryRequest) { + return null; + } + + @Override + public AssociateNatGatewayAddressResult associateNatGatewayAddress(AssociateNatGatewayAddressRequest associateNatGatewayAddressRequest) { + return null; + } + @Override public AssociateRouteTableResult associateRouteTable(AssociateRouteTableRequest associateRouteTableRequest) { return null; @@ -135,6 +160,11 @@ public AssociateTransitGatewayMulticastDomainResult associateTransitGatewayMulti return null; } + @Override + public AssociateTransitGatewayPolicyTableResult associateTransitGatewayPolicyTable(AssociateTransitGatewayPolicyTableRequest associateTransitGatewayPolicyTableRequest) { + return null; + } + @Override public AssociateTransitGatewayRouteTableResult associateTransitGatewayRouteTable(AssociateTransitGatewayRouteTableRequest associateTransitGatewayRouteTableRequest) { return null; @@ -165,6 +195,11 @@ public AttachNetworkInterfaceResult attachNetworkInterface(AttachNetworkInterfac return null; } + @Override + public AttachVerifiedAccessTrustProviderResult attachVerifiedAccessTrustProvider(AttachVerifiedAccessTrustProviderRequest attachVerifiedAccessTrustProviderRequest) { + return null; + } + @Override public AttachVolumeResult attachVolume(AttachVolumeRequest attachVolumeRequest) { return null; @@ -220,6 +255,11 @@ public CancelExportTaskResult cancelExportTask(CancelExportTaskRequest cancelExp return null; } + @Override + public CancelImageLaunchPermissionResult cancelImageLaunchPermission(CancelImageLaunchPermissionRequest cancelImageLaunchPermissionRequest) { + return null; + } + @Override public CancelImportTaskResult cancelImportTask(CancelImportTaskRequest cancelImportTaskRequest) { return null; @@ -290,6 +330,16 @@ public CreateClientVpnRouteResult createClientVpnRoute(CreateClientVpnRouteReque return null; } + @Override + public CreateCoipCidrResult createCoipCidr(CreateCoipCidrRequest createCoipCidrRequest) { + return null; + } + + @Override + public CreateCoipPoolResult createCoipPool(CreateCoipPoolRequest createCoipPoolRequest) { + return null; + } + @Override public CreateCustomerGatewayResult createCustomerGateway(CreateCustomerGatewayRequest createCustomerGatewayRequest) { return null; @@ -335,6 +385,11 @@ public CreateImageResult createImage(CreateImageRequest createImageRequest) { return null; } + @Override + public CreateInstanceConnectEndpointResult createInstanceConnectEndpoint(CreateInstanceConnectEndpointRequest createInstanceConnectEndpointRequest) { + return null; + } + @Override public CreateInstanceEventWindowResult createInstanceEventWindow(CreateInstanceEventWindowRequest createInstanceEventWindowRequest) { return null; @@ -355,6 +410,26 @@ public CreateInternetGatewayResult createInternetGateway() { return null; } + @Override + public CreateIpamResult createIpam(CreateIpamRequest createIpamRequest) { + return null; + } + + @Override + public CreateIpamPoolResult createIpamPool(CreateIpamPoolRequest createIpamPoolRequest) { + return null; + } + + @Override + public CreateIpamResourceDiscoveryResult createIpamResourceDiscovery(CreateIpamResourceDiscoveryRequest createIpamResourceDiscoveryRequest) { + return null; + } + + @Override + public CreateIpamScopeResult createIpamScope(CreateIpamScopeRequest createIpamScopeRequest) { + return null; + } + @Override public CreateKeyPairResult createKeyPair(CreateKeyPairRequest createKeyPairRequest) { return null; @@ -375,6 +450,16 @@ public CreateLocalGatewayRouteResult createLocalGatewayRoute(CreateLocalGatewayR return null; } + @Override + public CreateLocalGatewayRouteTableResult createLocalGatewayRouteTable(CreateLocalGatewayRouteTableRequest createLocalGatewayRouteTableRequest) { + return null; + } + + @Override + public CreateLocalGatewayRouteTableVirtualInterfaceGroupAssociationResult createLocalGatewayRouteTableVirtualInterfaceGroupAssociation(CreateLocalGatewayRouteTableVirtualInterfaceGroupAssociationRequest createLocalGatewayRouteTableVirtualInterfaceGroupAssociationRequest) { + return null; + } + @Override public CreateLocalGatewayRouteTableVpcAssociationResult createLocalGatewayRouteTableVpcAssociation(CreateLocalGatewayRouteTableVpcAssociationRequest createLocalGatewayRouteTableVpcAssociationRequest) { return null; @@ -400,6 +485,11 @@ public CreateNetworkAclEntryResult createNetworkAclEntry(CreateNetworkAclEntryRe return null; } + @Override + public CreateNetworkInsightsAccessScopeResult createNetworkInsightsAccessScope(CreateNetworkInsightsAccessScopeRequest createNetworkInsightsAccessScopeRequest) { + return null; + } + @Override public CreateNetworkInsightsPathResult createNetworkInsightsPath(CreateNetworkInsightsPathRequest createNetworkInsightsPathRequest) { return null; @@ -420,6 +510,11 @@ public CreatePlacementGroupResult createPlacementGroup(CreatePlacementGroupReque return null; } + @Override + public CreatePublicIpv4PoolResult createPublicIpv4Pool(CreatePublicIpv4PoolRequest createPublicIpv4PoolRequest) { + return null; + } + @Override public CreateReplaceRootVolumeTaskResult createReplaceRootVolumeTask(CreateReplaceRootVolumeTaskRequest createReplaceRootVolumeTaskRequest) { return null; @@ -530,6 +625,11 @@ public CreateTransitGatewayPeeringAttachmentResult createTransitGatewayPeeringAt return null; } + @Override + public CreateTransitGatewayPolicyTableResult createTransitGatewayPolicyTable(CreateTransitGatewayPolicyTableRequest createTransitGatewayPolicyTableRequest) { + return null; + } + @Override public CreateTransitGatewayPrefixListReferenceResult createTransitGatewayPrefixListReference(CreateTransitGatewayPrefixListReferenceRequest createTransitGatewayPrefixListReferenceRequest) { return null; @@ -545,11 +645,36 @@ public CreateTransitGatewayRouteTableResult createTransitGatewayRouteTable(Creat return null; } + @Override + public CreateTransitGatewayRouteTableAnnouncementResult createTransitGatewayRouteTableAnnouncement(CreateTransitGatewayRouteTableAnnouncementRequest createTransitGatewayRouteTableAnnouncementRequest) { + return null; + } + @Override public CreateTransitGatewayVpcAttachmentResult createTransitGatewayVpcAttachment(CreateTransitGatewayVpcAttachmentRequest createTransitGatewayVpcAttachmentRequest) { return null; } + @Override + public CreateVerifiedAccessEndpointResult createVerifiedAccessEndpoint(CreateVerifiedAccessEndpointRequest createVerifiedAccessEndpointRequest) { + return null; + } + + @Override + public CreateVerifiedAccessGroupResult createVerifiedAccessGroup(CreateVerifiedAccessGroupRequest createVerifiedAccessGroupRequest) { + return null; + } + + @Override + public CreateVerifiedAccessInstanceResult createVerifiedAccessInstance(CreateVerifiedAccessInstanceRequest createVerifiedAccessInstanceRequest) { + return null; + } + + @Override + public CreateVerifiedAccessTrustProviderResult createVerifiedAccessTrustProvider(CreateVerifiedAccessTrustProviderRequest createVerifiedAccessTrustProviderRequest) { + return null; + } + @Override public CreateVolumeResult createVolume(CreateVolumeRequest createVolumeRequest) { return null; @@ -615,6 +740,16 @@ public DeleteClientVpnRouteResult deleteClientVpnRoute(DeleteClientVpnRouteReque return null; } + @Override + public DeleteCoipCidrResult deleteCoipCidr(DeleteCoipCidrRequest deleteCoipCidrRequest) { + return null; + } + + @Override + public DeleteCoipPoolResult deleteCoipPool(DeleteCoipPoolRequest deleteCoipPoolRequest) { + return null; + } + @Override public DeleteCustomerGatewayResult deleteCustomerGateway(DeleteCustomerGatewayRequest deleteCustomerGatewayRequest) { return null; @@ -645,6 +780,11 @@ public DeleteFpgaImageResult deleteFpgaImage(DeleteFpgaImageRequest deleteFpgaIm return null; } + @Override + public DeleteInstanceConnectEndpointResult deleteInstanceConnectEndpoint(DeleteInstanceConnectEndpointRequest deleteInstanceConnectEndpointRequest) { + return null; + } + @Override public DeleteInstanceEventWindowResult deleteInstanceEventWindow(DeleteInstanceEventWindowRequest deleteInstanceEventWindowRequest) { return null; @@ -655,6 +795,26 @@ public DeleteInternetGatewayResult deleteInternetGateway(DeleteInternetGatewayRe return null; } + @Override + public DeleteIpamResult deleteIpam(DeleteIpamRequest deleteIpamRequest) { + return null; + } + + @Override + public DeleteIpamPoolResult deleteIpamPool(DeleteIpamPoolRequest deleteIpamPoolRequest) { + return null; + } + + @Override + public DeleteIpamResourceDiscoveryResult deleteIpamResourceDiscovery(DeleteIpamResourceDiscoveryRequest deleteIpamResourceDiscoveryRequest) { + return null; + } + + @Override + public DeleteIpamScopeResult deleteIpamScope(DeleteIpamScopeRequest deleteIpamScopeRequest) { + return null; + } + @Override public DeleteKeyPairResult deleteKeyPair(DeleteKeyPairRequest deleteKeyPairRequest) { return null; @@ -675,6 +835,16 @@ public DeleteLocalGatewayRouteResult deleteLocalGatewayRoute(DeleteLocalGatewayR return null; } + @Override + public DeleteLocalGatewayRouteTableResult deleteLocalGatewayRouteTable(DeleteLocalGatewayRouteTableRequest deleteLocalGatewayRouteTableRequest) { + return null; + } + + @Override + public DeleteLocalGatewayRouteTableVirtualInterfaceGroupAssociationResult deleteLocalGatewayRouteTableVirtualInterfaceGroupAssociation(DeleteLocalGatewayRouteTableVirtualInterfaceGroupAssociationRequest deleteLocalGatewayRouteTableVirtualInterfaceGroupAssociationRequest) { + return null; + } + @Override public DeleteLocalGatewayRouteTableVpcAssociationResult deleteLocalGatewayRouteTableVpcAssociation(DeleteLocalGatewayRouteTableVpcAssociationRequest deleteLocalGatewayRouteTableVpcAssociationRequest) { return null; @@ -700,6 +870,16 @@ public DeleteNetworkAclEntryResult deleteNetworkAclEntry(DeleteNetworkAclEntryRe return null; } + @Override + public DeleteNetworkInsightsAccessScopeResult deleteNetworkInsightsAccessScope(DeleteNetworkInsightsAccessScopeRequest deleteNetworkInsightsAccessScopeRequest) { + return null; + } + + @Override + public DeleteNetworkInsightsAccessScopeAnalysisResult deleteNetworkInsightsAccessScopeAnalysis(DeleteNetworkInsightsAccessScopeAnalysisRequest deleteNetworkInsightsAccessScopeAnalysisRequest) { + return null; + } + @Override public DeleteNetworkInsightsAnalysisResult deleteNetworkInsightsAnalysis(DeleteNetworkInsightsAnalysisRequest deleteNetworkInsightsAnalysisRequest) { return null; @@ -725,6 +905,11 @@ public DeletePlacementGroupResult deletePlacementGroup(DeletePlacementGroupReque return null; } + @Override + public DeletePublicIpv4PoolResult deletePublicIpv4Pool(DeletePublicIpv4PoolRequest deletePublicIpv4PoolRequest) { + return null; + } + @Override public DeleteQueuedReservedInstancesResult deleteQueuedReservedInstances(DeleteQueuedReservedInstancesRequest deleteQueuedReservedInstancesRequest) { return null; @@ -820,6 +1005,11 @@ public DeleteTransitGatewayPeeringAttachmentResult deleteTransitGatewayPeeringAt return null; } + @Override + public DeleteTransitGatewayPolicyTableResult deleteTransitGatewayPolicyTable(DeleteTransitGatewayPolicyTableRequest deleteTransitGatewayPolicyTableRequest) { + return null; + } + @Override public DeleteTransitGatewayPrefixListReferenceResult deleteTransitGatewayPrefixListReference(DeleteTransitGatewayPrefixListReferenceRequest deleteTransitGatewayPrefixListReferenceRequest) { return null; @@ -835,11 +1025,36 @@ public DeleteTransitGatewayRouteTableResult deleteTransitGatewayRouteTable(Delet return null; } + @Override + public DeleteTransitGatewayRouteTableAnnouncementResult deleteTransitGatewayRouteTableAnnouncement(DeleteTransitGatewayRouteTableAnnouncementRequest deleteTransitGatewayRouteTableAnnouncementRequest) { + return null; + } + @Override public DeleteTransitGatewayVpcAttachmentResult deleteTransitGatewayVpcAttachment(DeleteTransitGatewayVpcAttachmentRequest deleteTransitGatewayVpcAttachmentRequest) { return null; } + @Override + public DeleteVerifiedAccessEndpointResult deleteVerifiedAccessEndpoint(DeleteVerifiedAccessEndpointRequest deleteVerifiedAccessEndpointRequest) { + return null; + } + + @Override + public DeleteVerifiedAccessGroupResult deleteVerifiedAccessGroup(DeleteVerifiedAccessGroupRequest deleteVerifiedAccessGroupRequest) { + return null; + } + + @Override + public DeleteVerifiedAccessInstanceResult deleteVerifiedAccessInstance(DeleteVerifiedAccessInstanceRequest deleteVerifiedAccessInstanceRequest) { + return null; + } + + @Override + public DeleteVerifiedAccessTrustProviderResult deleteVerifiedAccessTrustProvider(DeleteVerifiedAccessTrustProviderRequest deleteVerifiedAccessTrustProviderRequest) { + return null; + } + @Override public DeleteVolumeResult deleteVolume(DeleteVolumeRequest deleteVolumeRequest) { return null; @@ -890,6 +1105,16 @@ public DeprovisionByoipCidrResult deprovisionByoipCidr(DeprovisionByoipCidrReque return null; } + @Override + public DeprovisionIpamPoolCidrResult deprovisionIpamPoolCidr(DeprovisionIpamPoolCidrRequest deprovisionIpamPoolCidrRequest) { + return null; + } + + @Override + public DeprovisionPublicIpv4PoolCidrResult deprovisionPublicIpv4PoolCidr(DeprovisionPublicIpv4PoolCidrRequest deprovisionPublicIpv4PoolCidrRequest) { + return null; + } + @Override public DeregisterImageResult deregisterImage(DeregisterImageRequest deregisterImageRequest) { return null; @@ -920,6 +1145,11 @@ public DescribeAccountAttributesResult describeAccountAttributes() { return null; } + @Override + public DescribeAddressTransfersResult describeAddressTransfers(DescribeAddressTransfersRequest describeAddressTransfersRequest) { + return null; + } + @Override public DescribeAddressesResult describeAddresses(DescribeAddressesRequest describeAddressesRequest) { return null; @@ -950,6 +1180,11 @@ public DescribeAvailabilityZonesResult describeAvailabilityZones() { return null; } + @Override + public DescribeAwsNetworkPerformanceMetricSubscriptionsResult describeAwsNetworkPerformanceMetricSubscriptions(DescribeAwsNetworkPerformanceMetricSubscriptionsRequest describeAwsNetworkPerformanceMetricSubscriptionsRequest) { + return null; + } + @Override public DescribeBundleTasksResult describeBundleTasks(DescribeBundleTasksRequest describeBundleTasksRequest) { return null; @@ -1075,6 +1310,11 @@ public DescribeExportTasksResult describeExportTasks() { return null; } + @Override + public DescribeFastLaunchImagesResult describeFastLaunchImages(DescribeFastLaunchImagesRequest describeFastLaunchImagesRequest) { + return null; + } + @Override public DescribeFastSnapshotRestoresResult describeFastSnapshotRestores(DescribeFastSnapshotRestoresRequest describeFastSnapshotRestoresRequest) { return null; @@ -1195,6 +1435,11 @@ public DescribeInstanceAttributeResult describeInstanceAttribute(DescribeInstanc return null; } + @Override + public DescribeInstanceConnectEndpointsResult describeInstanceConnectEndpoints(DescribeInstanceConnectEndpointsRequest describeInstanceConnectEndpointsRequest) { + return null; + } + @Override public DescribeInstanceCreditSpecificationsResult describeInstanceCreditSpecifications(DescribeInstanceCreditSpecificationsRequest describeInstanceCreditSpecificationsRequest) { return null; @@ -1250,6 +1495,31 @@ public DescribeInternetGatewaysResult describeInternetGateways() { return null; } + @Override + public DescribeIpamPoolsResult describeIpamPools(DescribeIpamPoolsRequest describeIpamPoolsRequest) { + return null; + } + + @Override + public DescribeIpamResourceDiscoveriesResult describeIpamResourceDiscoveries(DescribeIpamResourceDiscoveriesRequest describeIpamResourceDiscoveriesRequest) { + return null; + } + + @Override + public DescribeIpamResourceDiscoveryAssociationsResult describeIpamResourceDiscoveryAssociations(DescribeIpamResourceDiscoveryAssociationsRequest describeIpamResourceDiscoveryAssociationsRequest) { + return null; + } + + @Override + public DescribeIpamScopesResult describeIpamScopes(DescribeIpamScopesRequest describeIpamScopesRequest) { + return null; + } + + @Override + public DescribeIpamsResult describeIpams(DescribeIpamsRequest describeIpamsRequest) { + return null; + } + @Override public DescribeIpv6PoolsResult describeIpv6Pools(DescribeIpv6PoolsRequest describeIpv6PoolsRequest) { return null; @@ -1335,6 +1605,16 @@ public DescribeNetworkAclsResult describeNetworkAcls() { return null; } + @Override + public DescribeNetworkInsightsAccessScopeAnalysesResult describeNetworkInsightsAccessScopeAnalyses(DescribeNetworkInsightsAccessScopeAnalysesRequest describeNetworkInsightsAccessScopeAnalysesRequest) { + return null; + } + + @Override + public DescribeNetworkInsightsAccessScopesResult describeNetworkInsightsAccessScopes(DescribeNetworkInsightsAccessScopesRequest describeNetworkInsightsAccessScopesRequest) { + return null; + } + @Override public DescribeNetworkInsightsAnalysesResult describeNetworkInsightsAnalyses(DescribeNetworkInsightsAnalysesRequest describeNetworkInsightsAnalysesRequest) { return null; @@ -1495,6 +1775,11 @@ public DescribeSnapshotAttributeResult describeSnapshotAttribute(DescribeSnapsho return null; } + @Override + public DescribeSnapshotTierStatusResult describeSnapshotTierStatus(DescribeSnapshotTierStatusRequest describeSnapshotTierStatusRequest) { + return null; + } + @Override public DescribeSnapshotsResult describeSnapshots(DescribeSnapshotsRequest describeSnapshotsRequest) { return null; @@ -1625,6 +1910,16 @@ public DescribeTransitGatewayPeeringAttachmentsResult describeTransitGatewayPeer return null; } + @Override + public DescribeTransitGatewayPolicyTablesResult describeTransitGatewayPolicyTables(DescribeTransitGatewayPolicyTablesRequest describeTransitGatewayPolicyTablesRequest) { + return null; + } + + @Override + public DescribeTransitGatewayRouteTableAnnouncementsResult describeTransitGatewayRouteTableAnnouncements(DescribeTransitGatewayRouteTableAnnouncementsRequest describeTransitGatewayRouteTableAnnouncementsRequest) { + return null; + } + @Override public DescribeTransitGatewayRouteTablesResult describeTransitGatewayRouteTables(DescribeTransitGatewayRouteTablesRequest describeTransitGatewayRouteTablesRequest) { return null; @@ -1645,6 +1940,31 @@ public DescribeTrunkInterfaceAssociationsResult describeTrunkInterfaceAssociatio return null; } + @Override + public DescribeVerifiedAccessEndpointsResult describeVerifiedAccessEndpoints(DescribeVerifiedAccessEndpointsRequest describeVerifiedAccessEndpointsRequest) { + return null; + } + + @Override + public DescribeVerifiedAccessGroupsResult describeVerifiedAccessGroups(DescribeVerifiedAccessGroupsRequest describeVerifiedAccessGroupsRequest) { + return null; + } + + @Override + public DescribeVerifiedAccessInstanceLoggingConfigurationsResult describeVerifiedAccessInstanceLoggingConfigurations(DescribeVerifiedAccessInstanceLoggingConfigurationsRequest describeVerifiedAccessInstanceLoggingConfigurationsRequest) { + return null; + } + + @Override + public DescribeVerifiedAccessInstancesResult describeVerifiedAccessInstances(DescribeVerifiedAccessInstancesRequest describeVerifiedAccessInstancesRequest) { + return null; + } + + @Override + public DescribeVerifiedAccessTrustProvidersResult describeVerifiedAccessTrustProviders(DescribeVerifiedAccessTrustProvidersRequest describeVerifiedAccessTrustProvidersRequest) { + return null; + } + @Override public DescribeVolumeAttributeResult describeVolumeAttribute(DescribeVolumeAttributeRequest describeVolumeAttributeRequest) { return null; @@ -1790,6 +2110,11 @@ public DetachNetworkInterfaceResult detachNetworkInterface(DetachNetworkInterfac return null; } + @Override + public DetachVerifiedAccessTrustProviderResult detachVerifiedAccessTrustProvider(DetachVerifiedAccessTrustProviderRequest detachVerifiedAccessTrustProviderRequest) { + return null; + } + @Override public DetachVolumeResult detachVolume(DetachVolumeRequest detachVolumeRequest) { return null; @@ -1800,11 +2125,26 @@ public DetachVpnGatewayResult detachVpnGateway(DetachVpnGatewayRequest detachVpn return null; } + @Override + public DisableAddressTransferResult disableAddressTransfer(DisableAddressTransferRequest disableAddressTransferRequest) { + return null; + } + + @Override + public DisableAwsNetworkPerformanceMetricSubscriptionResult disableAwsNetworkPerformanceMetricSubscription(DisableAwsNetworkPerformanceMetricSubscriptionRequest disableAwsNetworkPerformanceMetricSubscriptionRequest) { + return null; + } + @Override public DisableEbsEncryptionByDefaultResult disableEbsEncryptionByDefault(DisableEbsEncryptionByDefaultRequest disableEbsEncryptionByDefaultRequest) { return null; } + @Override + public DisableFastLaunchResult disableFastLaunch(DisableFastLaunchRequest disableFastLaunchRequest) { + return null; + } + @Override public DisableFastSnapshotRestoresResult disableFastSnapshotRestores(DisableFastSnapshotRestoresRequest disableFastSnapshotRestoresRequest) { return null; @@ -1815,6 +2155,11 @@ public DisableImageDeprecationResult disableImageDeprecation(DisableImageDepreca return null; } + @Override + public DisableIpamOrganizationAdminAccountResult disableIpamOrganizationAdminAccount(DisableIpamOrganizationAdminAccountRequest disableIpamOrganizationAdminAccountRequest) { + return null; + } + @Override public DisableSerialConsoleAccessResult disableSerialConsoleAccess(DisableSerialConsoleAccessRequest disableSerialConsoleAccessRequest) { return null; @@ -1865,6 +2210,16 @@ public DisassociateInstanceEventWindowResult disassociateInstanceEventWindow(Dis return null; } + @Override + public DisassociateIpamResourceDiscoveryResult disassociateIpamResourceDiscovery(DisassociateIpamResourceDiscoveryRequest disassociateIpamResourceDiscoveryRequest) { + return null; + } + + @Override + public DisassociateNatGatewayAddressResult disassociateNatGatewayAddress(DisassociateNatGatewayAddressRequest disassociateNatGatewayAddressRequest) { + return null; + } + @Override public DisassociateRouteTableResult disassociateRouteTable(DisassociateRouteTableRequest disassociateRouteTableRequest) { return null; @@ -1880,6 +2235,11 @@ public DisassociateTransitGatewayMulticastDomainResult disassociateTransitGatewa return null; } + @Override + public DisassociateTransitGatewayPolicyTableResult disassociateTransitGatewayPolicyTable(DisassociateTransitGatewayPolicyTableRequest disassociateTransitGatewayPolicyTableRequest) { + return null; + } + @Override public DisassociateTransitGatewayRouteTableResult disassociateTransitGatewayRouteTable(DisassociateTransitGatewayRouteTableRequest disassociateTransitGatewayRouteTableRequest) { return null; @@ -1895,11 +2255,26 @@ public DisassociateVpcCidrBlockResult disassociateVpcCidrBlock(DisassociateVpcCi return null; } + @Override + public EnableAddressTransferResult enableAddressTransfer(EnableAddressTransferRequest enableAddressTransferRequest) { + return null; + } + + @Override + public EnableAwsNetworkPerformanceMetricSubscriptionResult enableAwsNetworkPerformanceMetricSubscription(EnableAwsNetworkPerformanceMetricSubscriptionRequest enableAwsNetworkPerformanceMetricSubscriptionRequest) { + return null; + } + @Override public EnableEbsEncryptionByDefaultResult enableEbsEncryptionByDefault(EnableEbsEncryptionByDefaultRequest enableEbsEncryptionByDefaultRequest) { return null; } + @Override + public EnableFastLaunchResult enableFastLaunch(EnableFastLaunchRequest enableFastLaunchRequest) { + return null; + } + @Override public EnableFastSnapshotRestoresResult enableFastSnapshotRestores(EnableFastSnapshotRestoresRequest enableFastSnapshotRestoresRequest) { return null; @@ -1910,6 +2285,16 @@ public EnableImageDeprecationResult enableImageDeprecation(EnableImageDeprecatio return null; } + @Override + public EnableIpamOrganizationAdminAccountResult enableIpamOrganizationAdminAccount(EnableIpamOrganizationAdminAccountRequest enableIpamOrganizationAdminAccountRequest) { + return null; + } + + @Override + public EnableReachabilityAnalyzerOrganizationSharingResult enableReachabilityAnalyzerOrganizationSharing(EnableReachabilityAnalyzerOrganizationSharingRequest enableReachabilityAnalyzerOrganizationSharingRequest) { + return null; + } + @Override public EnableSerialConsoleAccessResult enableSerialConsoleAccess(EnableSerialConsoleAccessRequest enableSerialConsoleAccessRequest) { return null; @@ -1970,6 +2355,11 @@ public GetAssociatedIpv6PoolCidrsResult getAssociatedIpv6PoolCidrs(GetAssociated return null; } + @Override + public GetAwsNetworkPerformanceDataResult getAwsNetworkPerformanceData(GetAwsNetworkPerformanceDataRequest getAwsNetworkPerformanceDataRequest) { + return null; + } + @Override public GetCapacityReservationUsageResult getCapacityReservationUsage(GetCapacityReservationUsageRequest getCapacityReservationUsageRequest) { return null; @@ -2025,6 +2415,41 @@ public GetInstanceTypesFromInstanceRequirementsResult getInstanceTypesFromInstan return null; } + @Override + public GetInstanceUefiDataResult getInstanceUefiData(GetInstanceUefiDataRequest getInstanceUefiDataRequest) { + return null; + } + + @Override + public GetIpamAddressHistoryResult getIpamAddressHistory(GetIpamAddressHistoryRequest getIpamAddressHistoryRequest) { + return null; + } + + @Override + public GetIpamDiscoveredAccountsResult getIpamDiscoveredAccounts(GetIpamDiscoveredAccountsRequest getIpamDiscoveredAccountsRequest) { + return null; + } + + @Override + public GetIpamDiscoveredResourceCidrsResult getIpamDiscoveredResourceCidrs(GetIpamDiscoveredResourceCidrsRequest getIpamDiscoveredResourceCidrsRequest) { + return null; + } + + @Override + public GetIpamPoolAllocationsResult getIpamPoolAllocations(GetIpamPoolAllocationsRequest getIpamPoolAllocationsRequest) { + return null; + } + + @Override + public GetIpamPoolCidrsResult getIpamPoolCidrs(GetIpamPoolCidrsRequest getIpamPoolCidrsRequest) { + return null; + } + + @Override + public GetIpamResourceCidrsResult getIpamResourceCidrs(GetIpamResourceCidrsRequest getIpamResourceCidrsRequest) { + return null; + } + @Override public GetLaunchTemplateDataResult getLaunchTemplateData(GetLaunchTemplateDataRequest getLaunchTemplateDataRequest) { return null; @@ -2040,6 +2465,16 @@ public GetManagedPrefixListEntriesResult getManagedPrefixListEntries(GetManagedP return null; } + @Override + public GetNetworkInsightsAccessScopeAnalysisFindingsResult getNetworkInsightsAccessScopeAnalysisFindings(GetNetworkInsightsAccessScopeAnalysisFindingsRequest getNetworkInsightsAccessScopeAnalysisFindingsRequest) { + return null; + } + + @Override + public GetNetworkInsightsAccessScopeContentResult getNetworkInsightsAccessScopeContent(GetNetworkInsightsAccessScopeContentRequest getNetworkInsightsAccessScopeContentRequest) { + return null; + } + @Override public GetPasswordDataResult getPasswordData(GetPasswordDataRequest getPasswordDataRequest) { return null; @@ -2075,6 +2510,16 @@ public GetTransitGatewayMulticastDomainAssociationsResult getTransitGatewayMulti return null; } + @Override + public GetTransitGatewayPolicyTableAssociationsResult getTransitGatewayPolicyTableAssociations(GetTransitGatewayPolicyTableAssociationsRequest getTransitGatewayPolicyTableAssociationsRequest) { + return null; + } + + @Override + public GetTransitGatewayPolicyTableEntriesResult getTransitGatewayPolicyTableEntries(GetTransitGatewayPolicyTableEntriesRequest getTransitGatewayPolicyTableEntriesRequest) { + return null; + } + @Override public GetTransitGatewayPrefixListReferencesResult getTransitGatewayPrefixListReferences(GetTransitGatewayPrefixListReferencesRequest getTransitGatewayPrefixListReferencesRequest) { return null; @@ -2090,6 +2535,16 @@ public GetTransitGatewayRouteTablePropagationsResult getTransitGatewayRouteTable return null; } + @Override + public GetVerifiedAccessEndpointPolicyResult getVerifiedAccessEndpointPolicy(GetVerifiedAccessEndpointPolicyRequest getVerifiedAccessEndpointPolicyRequest) { + return null; + } + + @Override + public GetVerifiedAccessGroupPolicyResult getVerifiedAccessGroupPolicy(GetVerifiedAccessGroupPolicyRequest getVerifiedAccessGroupPolicyRequest) { + return null; + } + @Override public GetVpnConnectionDeviceSampleConfigurationResult getVpnConnectionDeviceSampleConfiguration(GetVpnConnectionDeviceSampleConfigurationRequest getVpnConnectionDeviceSampleConfigurationRequest) { return null; @@ -2100,6 +2555,11 @@ public GetVpnConnectionDeviceTypesResult getVpnConnectionDeviceTypes(GetVpnConne return null; } + @Override + public GetVpnTunnelReplacementStatusResult getVpnTunnelReplacementStatus(GetVpnTunnelReplacementStatusRequest getVpnTunnelReplacementStatusRequest) { + return null; + } + @Override public ImportClientVpnClientCertificateRevocationListResult importClientVpnClientCertificateRevocationList(ImportClientVpnClientCertificateRevocationListRequest importClientVpnClientCertificateRevocationListRequest) { return null; @@ -2140,6 +2600,16 @@ public ImportVolumeResult importVolume(ImportVolumeRequest importVolumeRequest) return null; } + @Override + public ListImagesInRecycleBinResult listImagesInRecycleBin(ListImagesInRecycleBinRequest listImagesInRecycleBinRequest) { + return null; + } + + @Override + public ListSnapshotsInRecycleBinResult listSnapshotsInRecycleBin(ListSnapshotsInRecycleBinRequest listSnapshotsInRecycleBinRequest) { + return null; + } + @Override public ModifyAddressAttributeResult modifyAddressAttribute(ModifyAddressAttributeRequest modifyAddressAttributeRequest) { return null; @@ -2230,6 +2700,11 @@ public ModifyInstanceEventWindowResult modifyInstanceEventWindow(ModifyInstanceE return null; } + @Override + public ModifyInstanceMaintenanceOptionsResult modifyInstanceMaintenanceOptions(ModifyInstanceMaintenanceOptionsRequest modifyInstanceMaintenanceOptionsRequest) { + return null; + } + @Override public ModifyInstanceMetadataOptionsResult modifyInstanceMetadataOptions(ModifyInstanceMetadataOptionsRequest modifyInstanceMetadataOptionsRequest) { return null; @@ -2240,11 +2715,41 @@ public ModifyInstancePlacementResult modifyInstancePlacement(ModifyInstancePlace return null; } + @Override + public ModifyIpamResult modifyIpam(ModifyIpamRequest modifyIpamRequest) { + return null; + } + + @Override + public ModifyIpamPoolResult modifyIpamPool(ModifyIpamPoolRequest modifyIpamPoolRequest) { + return null; + } + + @Override + public ModifyIpamResourceCidrResult modifyIpamResourceCidr(ModifyIpamResourceCidrRequest modifyIpamResourceCidrRequest) { + return null; + } + + @Override + public ModifyIpamResourceDiscoveryResult modifyIpamResourceDiscovery(ModifyIpamResourceDiscoveryRequest modifyIpamResourceDiscoveryRequest) { + return null; + } + + @Override + public ModifyIpamScopeResult modifyIpamScope(ModifyIpamScopeRequest modifyIpamScopeRequest) { + return null; + } + @Override public ModifyLaunchTemplateResult modifyLaunchTemplate(ModifyLaunchTemplateRequest modifyLaunchTemplateRequest) { return null; } + @Override + public ModifyLocalGatewayRouteResult modifyLocalGatewayRoute(ModifyLocalGatewayRouteRequest modifyLocalGatewayRouteRequest) { + return null; + } + @Override public ModifyManagedPrefixListResult modifyManagedPrefixList(ModifyManagedPrefixListRequest modifyManagedPrefixListRequest) { return null; @@ -2255,6 +2760,11 @@ public ModifyNetworkInterfaceAttributeResult modifyNetworkInterfaceAttribute(Mod return null; } + @Override + public ModifyPrivateDnsNameOptionsResult modifyPrivateDnsNameOptions(ModifyPrivateDnsNameOptionsRequest modifyPrivateDnsNameOptionsRequest) { + return null; + } + @Override public ModifyReservedInstancesResult modifyReservedInstances(ModifyReservedInstancesRequest modifyReservedInstancesRequest) { return null; @@ -2270,6 +2780,11 @@ public ModifySnapshotAttributeResult modifySnapshotAttribute(ModifySnapshotAttri return null; } + @Override + public ModifySnapshotTierResult modifySnapshotTier(ModifySnapshotTierRequest modifySnapshotTierRequest) { + return null; + } + @Override public ModifySpotFleetRequestResult modifySpotFleetRequest(ModifySpotFleetRequestRequest modifySpotFleetRequestRequest) { return null; @@ -2310,6 +2825,41 @@ public ModifyTransitGatewayVpcAttachmentResult modifyTransitGatewayVpcAttachment return null; } + @Override + public ModifyVerifiedAccessEndpointResult modifyVerifiedAccessEndpoint(ModifyVerifiedAccessEndpointRequest modifyVerifiedAccessEndpointRequest) { + return null; + } + + @Override + public ModifyVerifiedAccessEndpointPolicyResult modifyVerifiedAccessEndpointPolicy(ModifyVerifiedAccessEndpointPolicyRequest modifyVerifiedAccessEndpointPolicyRequest) { + return null; + } + + @Override + public ModifyVerifiedAccessGroupResult modifyVerifiedAccessGroup(ModifyVerifiedAccessGroupRequest modifyVerifiedAccessGroupRequest) { + return null; + } + + @Override + public ModifyVerifiedAccessGroupPolicyResult modifyVerifiedAccessGroupPolicy(ModifyVerifiedAccessGroupPolicyRequest modifyVerifiedAccessGroupPolicyRequest) { + return null; + } + + @Override + public ModifyVerifiedAccessInstanceResult modifyVerifiedAccessInstance(ModifyVerifiedAccessInstanceRequest modifyVerifiedAccessInstanceRequest) { + return null; + } + + @Override + public ModifyVerifiedAccessInstanceLoggingConfigurationResult modifyVerifiedAccessInstanceLoggingConfiguration(ModifyVerifiedAccessInstanceLoggingConfigurationRequest modifyVerifiedAccessInstanceLoggingConfigurationRequest) { + return null; + } + + @Override + public ModifyVerifiedAccessTrustProviderResult modifyVerifiedAccessTrustProvider(ModifyVerifiedAccessTrustProviderRequest modifyVerifiedAccessTrustProviderRequest) { + return null; + } + @Override public ModifyVolumeResult modifyVolume(ModifyVolumeRequest modifyVolumeRequest) { return null; @@ -2340,6 +2890,11 @@ public ModifyVpcEndpointServiceConfigurationResult modifyVpcEndpointServiceConfi return null; } + @Override + public ModifyVpcEndpointServicePayerResponsibilityResult modifyVpcEndpointServicePayerResponsibility(ModifyVpcEndpointServicePayerResponsibilityRequest modifyVpcEndpointServicePayerResponsibilityRequest) { + return null; + } + @Override public ModifyVpcEndpointServicePermissionsResult modifyVpcEndpointServicePermissions(ModifyVpcEndpointServicePermissionsRequest modifyVpcEndpointServicePermissionsRequest) { return null; @@ -2385,11 +2940,26 @@ public MoveAddressToVpcResult moveAddressToVpc(MoveAddressToVpcRequest moveAddre return null; } + @Override + public MoveByoipCidrToIpamResult moveByoipCidrToIpam(MoveByoipCidrToIpamRequest moveByoipCidrToIpamRequest) { + return null; + } + @Override public ProvisionByoipCidrResult provisionByoipCidr(ProvisionByoipCidrRequest provisionByoipCidrRequest) { return null; } + @Override + public ProvisionIpamPoolCidrResult provisionIpamPoolCidr(ProvisionIpamPoolCidrRequest provisionIpamPoolCidrRequest) { + return null; + } + + @Override + public ProvisionPublicIpv4PoolCidrResult provisionPublicIpv4PoolCidr(ProvisionPublicIpv4PoolCidrRequest provisionPublicIpv4PoolCidrRequest) { + return null; + } + @Override public PurchaseHostReservationResult purchaseHostReservation(PurchaseHostReservationRequest purchaseHostReservationRequest) { return null; @@ -2465,6 +3035,11 @@ public ReleaseHostsResult releaseHosts(ReleaseHostsRequest releaseHostsRequest) return null; } + @Override + public ReleaseIpamPoolAllocationResult releaseIpamPoolAllocation(ReleaseIpamPoolAllocationRequest releaseIpamPoolAllocationRequest) { + return null; + } + @Override public ReplaceIamInstanceProfileAssociationResult replaceIamInstanceProfileAssociation(ReplaceIamInstanceProfileAssociationRequest replaceIamInstanceProfileAssociationRequest) { return null; @@ -2495,6 +3070,11 @@ public ReplaceTransitGatewayRouteResult replaceTransitGatewayRoute(ReplaceTransi return null; } + @Override + public ReplaceVpnTunnelResult replaceVpnTunnel(ReplaceVpnTunnelRequest replaceVpnTunnelRequest) { + return null; + } + @Override public ReportInstanceStatusResult reportInstanceStatus(ReportInstanceStatusRequest reportInstanceStatusRequest) { return null; @@ -2550,11 +3130,26 @@ public RestoreAddressToClassicResult restoreAddressToClassic(RestoreAddressToCla return null; } + @Override + public RestoreImageFromRecycleBinResult restoreImageFromRecycleBin(RestoreImageFromRecycleBinRequest restoreImageFromRecycleBinRequest) { + return null; + } + @Override public RestoreManagedPrefixListVersionResult restoreManagedPrefixListVersion(RestoreManagedPrefixListVersionRequest restoreManagedPrefixListVersionRequest) { return null; } + @Override + public RestoreSnapshotFromRecycleBinResult restoreSnapshotFromRecycleBin(RestoreSnapshotFromRecycleBinRequest restoreSnapshotFromRecycleBinRequest) { + return null; + } + + @Override + public RestoreSnapshotTierResult restoreSnapshotTier(RestoreSnapshotTierRequest restoreSnapshotTierRequest) { + return null; + } + @Override public RevokeClientVpnIngressResult revokeClientVpnIngress(RevokeClientVpnIngressRequest revokeClientVpnIngressRequest) { return null; @@ -2610,6 +3205,11 @@ public StartInstancesResult startInstances(StartInstancesRequest startInstancesR return null; } + @Override + public StartNetworkInsightsAccessScopeAnalysisResult startNetworkInsightsAccessScopeAnalysis(StartNetworkInsightsAccessScopeAnalysisRequest startNetworkInsightsAccessScopeAnalysisRequest) { + return null; + } + @Override public StartNetworkInsightsAnalysisResult startNetworkInsightsAnalysis(StartNetworkInsightsAnalysisRequest startNetworkInsightsAnalysisRequest) { return null; @@ -2645,6 +3245,11 @@ public UnassignPrivateIpAddressesResult unassignPrivateIpAddresses(UnassignPriva return null; } + @Override + public UnassignPrivateNatGatewayAddressResult unassignPrivateNatGatewayAddress(UnassignPrivateNatGatewayAddressRequest unassignPrivateNatGatewayAddressRequest) { + return null; + } + @Override public UnmonitorInstancesResult unmonitorInstances(UnmonitorInstancesRequest unmonitorInstancesRequest) { return null; diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/IntegrationTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/IntegrationTest.java index 62fd0ee8..b928d7a9 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/IntegrationTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/IntegrationTest.java @@ -32,8 +32,8 @@ import com.amazonaws.services.ec2.model.SpotFleetRequestConfigData; import com.amazonaws.services.ec2.model.TerminateInstancesRequest; import com.amazonaws.services.ec2.model.TerminateInstancesResult; -import com.gargoylesoftware.htmlunit.html.DomElement; -import com.gargoylesoftware.htmlunit.html.HtmlPage; +import org.htmlunit.html.DomElement; +import org.htmlunit.html.HtmlPage; import hudson.Functions; import hudson.model.AbstractBuild; import hudson.model.FreeStyleProject; diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategyTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategyTest.java index 66c487c7..9db44452 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategyTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategyTest.java @@ -10,8 +10,8 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.quality.Strictness; import java.util.ArrayList; import java.util.Arrays; @@ -28,9 +28,9 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.mockito.Mockito.withSettings; -@RunWith(PowerMockRunner.class) -@PrepareForTest({NodeProvisioner.StrategyState.class}) +@RunWith(MockitoJUnitRunner.class) public class NoDelayProvisionStrategyTest { @Mock @@ -160,7 +160,7 @@ public void givenEC2CloudsWhenOneCanCoverCapacity_shouldDoScalingForFirstOnly() final EC2FleetCloud ec2FleetCloud1 = mock(EC2FleetCloud.class); clouds.add(ec2FleetCloud1); - final EC2FleetCloud ec2FleetCloud2 = mock(EC2FleetCloud.class); + final EC2FleetCloud ec2FleetCloud2 = mock(EC2FleetCloud.class, withSettings().strictness(Strictness.LENIENT)); clouds.add(ec2FleetCloud2); when(ec2FleetCloud1.canProvision(any(Cloud.CloudState.class))).thenReturn(true); when(ec2FleetCloud2.canProvision(any(Cloud.CloudState.class))).thenReturn(true); diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/ProvisionIntegrationTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/ProvisionIntegrationTest.java index 66094aee..27b58b4e 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/ProvisionIntegrationTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/ProvisionIntegrationTest.java @@ -275,7 +275,7 @@ public void should_not_convert_planned_to_node_if_state_is_not_running_and_check tryUntil(new Runnable() { @Override public void run() { - Assert.assertEquals(new HashSet<>(Arrays.asList("master", "momo")), labelsToNames(j.jenkins.getLabels())); + Assert.assertEquals(new HashSet<>(Arrays.asList("built-in", "momo")), labelsToNames(j.jenkins.getLabels())); Assert.assertEquals(1, j.jenkins.getLabelAtom("momo").nodeProvisioner.getPendingLaunches().size()); Assert.assertEquals(0, j.jenkins.getNodes().size()); } @@ -310,7 +310,7 @@ public void should_successfully_create_nodes() throws Exception { tryUntil(new Runnable() { @Override public void run() { - Assert.assertEquals(new HashSet<>(Arrays.asList("master", "momo", "i-0", "i-1")), labelsToNames(j.jenkins.getLabels())); + Assert.assertEquals(new HashSet<>(Arrays.asList("built-in", "momo", "i-0", "i-1")), labelsToNames(j.jenkins.getLabels())); Assert.assertEquals(2, j.jenkins.getLabelAtom("momo").getNodes().size()); // node name should be instance name Assert.assertEquals(new HashSet<>(Arrays.asList("i-0", "i-1")), nodeToNames(j.jenkins.getLabelAtom("momo").getNodes())); diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/UiIntegrationTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/UiIntegrationTest.java index 2a8135dd..89414f0f 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/UiIntegrationTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/UiIntegrationTest.java @@ -5,11 +5,11 @@ import com.amazon.jenkins.ec2fleet.fleet.EC2Fleets; import com.amazonaws.services.ec2.AmazonEC2; -import com.gargoylesoftware.htmlunit.html.DomElement; -import com.gargoylesoftware.htmlunit.html.HtmlForm; -import com.gargoylesoftware.htmlunit.html.HtmlFormUtil; -import com.gargoylesoftware.htmlunit.html.HtmlPage; -import com.gargoylesoftware.htmlunit.html.HtmlTextInput; +import org.htmlunit.html.DomElement; +import org.htmlunit.html.HtmlForm; +import org.htmlunit.html.HtmlFormUtil; +import org.htmlunit.html.HtmlPage; +import org.htmlunit.html.HtmlTextInput; import hudson.PluginWrapper; import hudson.model.Node; import hudson.slaves.Cloud; diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/aws/EC2ApiTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/aws/EC2ApiTest.java index 8c50f893..7f435cdd 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/aws/EC2ApiTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/aws/EC2ApiTest.java @@ -29,8 +29,8 @@ import static org.mockito.Mockito.any; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; @SuppressWarnings("ArraysAsListWithZeroOrOneArgument") @@ -45,7 +45,7 @@ public void describeInstances_shouldReturnEmptyResultAndNoCallIfEmptyListOfInsta Map described = new EC2Api().describeInstances(amazonEC2, Collections.emptySet()); Assert.assertEquals(Collections.emptyMap(), described); - verifyZeroInteractions(amazonEC2); + verifyNoInteractions(amazonEC2); } @Test @@ -321,7 +321,7 @@ public void tagInstances_shouldDoNothingIfNoInstancesPassed() { new EC2Api().tagInstances(amazonEC2, Collections.emptySet(), "opa", "v"); // then - verifyZeroInteractions(amazonEC2); + verifyNoInteractions(amazonEC2); } @Test diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/fleet/AutoScalingGroupFleetTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/fleet/AutoScalingGroupFleetTest.java index 8d8c120d..ce0a31f9 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/fleet/AutoScalingGroupFleetTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/fleet/AutoScalingGroupFleetTest.java @@ -5,10 +5,10 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mockStatic; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.powermock.api.mockito.PowerMockito.mockStatic; import java.util.ArrayList; import java.util.Arrays; @@ -33,17 +33,25 @@ import com.cloudbees.jenkins.plugins.awscredentials.AmazonWebServicesCredentials; import hudson.util.ListBoxModel; import jenkins.model.Jenkins; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; +import org.mockito.MockedConstruction; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; -@RunWith(PowerMockRunner.class) -@PrepareForTest({ AWSUtils.class, AWSCredentialsHelper.class, AutoScalingGroupFleet.class, Jenkins.class }) +@RunWith(MockitoJUnitRunner.class) public class AutoScalingGroupFleetTest { + + private MockedStatic mockedJenkins; + + private MockedStatic mockedAWSCredentialsHelper; + + private MockedStatic mockedAWSUtils; + private static final String ENDPOINT = "fake-endpoint"; private static final String REGION = "fake-region"; private static final String CREDS_ID = "cred-Id"; @@ -54,55 +62,56 @@ public class AutoScalingGroupFleetTest { @Mock private AmazonWebServicesCredentials amazonWebServicesCredentials; @Mock - private AmazonAutoScalingClient autoScalingClient; - @Mock private ClientConfiguration clientConfiguration; @Before public void before() { - mockStatic(AWSUtils.class); - mockStatic(AWSCredentialsHelper.class); - mockStatic(Jenkins.class); - when(Jenkins.get()).thenReturn(jenkins); - when(AWSUtils.getClientConfiguration(ENDPOINT)).thenReturn(clientConfiguration); + mockedJenkins = mockStatic(Jenkins.class); + mockedJenkins.when(Jenkins::get).thenReturn(jenkins); + + mockedAWSUtils = mockStatic(AWSUtils.class); + mockedAWSUtils.when(() -> AWSUtils.getClientConfiguration(ENDPOINT)).thenReturn(clientConfiguration); + + mockedAWSCredentialsHelper = mockStatic(AWSCredentialsHelper.class); + } + + @After + public void after() { + mockedAWSCredentialsHelper.close(); + mockedAWSUtils.close(); + mockedJenkins.close(); } @Test public void createAsgClientWithInstanceProfileWhenCredsNull() throws Exception { - PowerMockito.whenNew(AmazonAutoScalingClient.class) - .withArguments(clientConfiguration) - .thenReturn(autoScalingClient); - - final AmazonAutoScalingClient result = new AutoScalingGroupFleet().createClient(null, REGION, ENDPOINT); - assertEquals(autoScalingClient, result); + try (MockedConstruction mockedAmazonAutoScalingClient = Mockito.mockConstruction(AmazonAutoScalingClient.class)) { + final AmazonAutoScalingClient result = new AutoScalingGroupFleet().createClient(null, REGION, ENDPOINT); + assertEquals(mockedAmazonAutoScalingClient.constructed().get(0), result); + } } @Test public void createAsgClientWithAWSCredentialsWhenCredentialIdExists() throws Exception { - when(AWSCredentialsHelper.getCredentials(CREDS_ID, jenkins)).thenReturn(amazonWebServicesCredentials); - - PowerMockito.whenNew(AmazonAutoScalingClient.class) - .withArguments(amazonWebServicesCredentials, clientConfiguration) - .thenReturn(autoScalingClient); + mockedAWSCredentialsHelper.when(() -> AWSCredentialsHelper.getCredentials(CREDS_ID, jenkins)).thenReturn(amazonWebServicesCredentials); - final AmazonAutoScalingClient result = new AutoScalingGroupFleet().createClient(CREDS_ID, REGION, ENDPOINT); - assertEquals(autoScalingClient, result); + try (MockedConstruction mockedAmazonAutoScalingClient = Mockito.mockConstruction(AmazonAutoScalingClient.class)) { + final AmazonAutoScalingClient result = new AutoScalingGroupFleet().createClient(CREDS_ID, REGION, ENDPOINT); + assertEquals(mockedAmazonAutoScalingClient.constructed().get(0), result); + } } @Test public void describeAutoScalingGroupsWithNoASG() throws Exception { final ListBoxModel listBoxModel = new ListBoxModel(); - when(AWSCredentialsHelper.getCredentials(CREDS_ID, jenkins)).thenReturn(amazonWebServicesCredentials); - - PowerMockito.whenNew(AmazonAutoScalingClient.class) - .withArguments(amazonWebServicesCredentials, clientConfiguration) - .thenReturn(autoScalingClient); + mockedAWSCredentialsHelper.when(() -> AWSCredentialsHelper.getCredentials(CREDS_ID, jenkins)).thenReturn(amazonWebServicesCredentials); - final DescribeAutoScalingGroupsResult result = new DescribeAutoScalingGroupsResult().withAutoScalingGroups(new ArrayList<>()); - when(autoScalingClient.describeAutoScalingGroups(any(DescribeAutoScalingGroupsRequest.class))).thenReturn(result); - - new AutoScalingGroupFleet().describe(CREDS_ID, REGION, ENDPOINT, listBoxModel, ASG_NAME, true); + try (MockedConstruction mockedAmazonAutoScalingClient = Mockito.mockConstruction(AmazonAutoScalingClient.class, (autoScalingClient, context) -> { + final DescribeAutoScalingGroupsResult result = new DescribeAutoScalingGroupsResult().withAutoScalingGroups(new ArrayList<>()); + when(autoScalingClient.describeAutoScalingGroups(any(DescribeAutoScalingGroupsRequest.class))).thenReturn(result); + })) { + new AutoScalingGroupFleet().describe(CREDS_ID, REGION, ENDPOINT, listBoxModel, ASG_NAME, true); + } // No ASG is displayed assertEquals(0, listBoxModel.size()); @@ -111,18 +120,16 @@ public void describeAutoScalingGroupsWithNoASG() throws Exception { @Test public void describeAutoScalingGroupsWithSingleASG() throws Exception { final String selectedAsgName = "selected-asg"; - when(AWSCredentialsHelper.getCredentials(CREDS_ID, jenkins)).thenReturn(amazonWebServicesCredentials); + mockedAWSCredentialsHelper.when(() -> AWSCredentialsHelper.getCredentials(CREDS_ID, jenkins)).thenReturn(amazonWebServicesCredentials); final ListBoxModel listBoxModel = new ListBoxModel(); - PowerMockito.whenNew(AmazonAutoScalingClient.class) - .withArguments(amazonWebServicesCredentials, clientConfiguration) - .thenReturn(autoScalingClient); - - final AutoScalingGroup asg = new AutoScalingGroup().withAutoScalingGroupName(selectedAsgName); - final DescribeAutoScalingGroupsResult result = new DescribeAutoScalingGroupsResult().withAutoScalingGroups(Collections.singleton(asg)); - when(autoScalingClient.describeAutoScalingGroups(any(DescribeAutoScalingGroupsRequest.class))).thenReturn(result); - - new AutoScalingGroupFleet().describe(CREDS_ID, REGION, ENDPOINT, listBoxModel, selectedAsgName, true); + try (MockedConstruction mockedAmazonAutoScalingClient = Mockito.mockConstruction(AmazonAutoScalingClient.class, (autoScalingClient, context) -> { + final AutoScalingGroup asg = new AutoScalingGroup().withAutoScalingGroupName(selectedAsgName); + final DescribeAutoScalingGroupsResult result = new DescribeAutoScalingGroupsResult().withAutoScalingGroups(Collections.singleton(asg)); + when(autoScalingClient.describeAutoScalingGroups(any(DescribeAutoScalingGroupsRequest.class))).thenReturn(result); + })) { + new AutoScalingGroupFleet().describe(CREDS_ID, REGION, ENDPOINT, listBoxModel, selectedAsgName, true); + } assertEquals(1, listBoxModel.size()); // verify the selected ASG is returned @@ -134,18 +141,18 @@ public void describeAutoScalingGroupsWithSingleASG() throws Exception { public void describeAutoScalingGroupsWithMultipleASG() throws Exception { final String selectedAsgName = "selected-asg"; - when(AWSCredentialsHelper.getCredentials(CREDS_ID, jenkins)).thenReturn(amazonWebServicesCredentials); + mockedAWSCredentialsHelper.when(() -> AWSCredentialsHelper.getCredentials(CREDS_ID, jenkins)).thenReturn(amazonWebServicesCredentials); ListBoxModel listBoxModel = new ListBoxModel(); - PowerMockito.whenNew(AmazonAutoScalingClient.class) - .withArguments(amazonWebServicesCredentials, clientConfiguration) - .thenReturn(autoScalingClient); - final AutoScalingGroup selectedAsg = new AutoScalingGroup().withAutoScalingGroupName(selectedAsgName); - final AutoScalingGroup asg = new AutoScalingGroup().withAutoScalingGroupName(ASG_NAME); - final List asgs = Arrays.asList(selectedAsg, asg); - final DescribeAutoScalingGroupsResult result = new DescribeAutoScalingGroupsResult().withAutoScalingGroups(asgs); - when(autoScalingClient.describeAutoScalingGroups(any(DescribeAutoScalingGroupsRequest.class))).thenReturn(result); - new AutoScalingGroupFleet().describe(CREDS_ID, REGION, ENDPOINT, listBoxModel, selectedAsgName, true); + try (MockedConstruction mockedAmazonAutoScalingClient = Mockito.mockConstruction(AmazonAutoScalingClient.class, (autoScalingClient, context) -> { + final AutoScalingGroup selectedAsg = new AutoScalingGroup().withAutoScalingGroupName(selectedAsgName); + final AutoScalingGroup asg = new AutoScalingGroup().withAutoScalingGroupName(ASG_NAME); + final List asgs = Arrays.asList(selectedAsg, asg); + final DescribeAutoScalingGroupsResult result = new DescribeAutoScalingGroupsResult().withAutoScalingGroups(asgs); + when(autoScalingClient.describeAutoScalingGroups(any(DescribeAutoScalingGroupsRequest.class))).thenReturn(result); + })) { + new AutoScalingGroupFleet().describe(CREDS_ID, REGION, ENDPOINT, listBoxModel, selectedAsgName, true); + } assertEquals(2, listBoxModel.size()); @@ -166,42 +173,39 @@ public void modifyAutoScalingGroupsShouldContainInstanceProtectedFromScaleIn() t final int min = 1; final int max = 5; - when(Jenkins.get()).thenReturn(jenkins); + mockedJenkins.when(Jenkins::get).thenReturn(jenkins); - when(AWSCredentialsHelper.getCredentials(CREDS_ID, jenkins)).thenReturn(amazonWebServicesCredentials); + mockedAWSCredentialsHelper.when(() -> AWSCredentialsHelper.getCredentials(CREDS_ID, jenkins)).thenReturn(amazonWebServicesCredentials); ListBoxModel listBoxModel = new ListBoxModel(); - PowerMockito.whenNew(AmazonAutoScalingClient.class) - .withArguments(amazonWebServicesCredentials, clientConfiguration) - .thenReturn(autoScalingClient); - - final UpdateAutoScalingGroupRequest requestWithoutScaleIn = new UpdateAutoScalingGroupRequest() - .withAutoScalingGroupName(ASG_NAME) - .withMinSize(min).withMaxSize(max) - .withDesiredCapacity(targetCapacity); - final UpdateAutoScalingGroupRequest requestWithScaleIn = new UpdateAutoScalingGroupRequest() - .withAutoScalingGroupName(ASG_NAME) - .withMinSize(min).withMaxSize(max) - .withDesiredCapacity(targetCapacity) - .withNewInstancesProtectedFromScaleIn(Boolean.TRUE); - new AutoScalingGroupFleet().modify(CREDS_ID, REGION, ENDPOINT, ASG_NAME, targetCapacity, min, max); - verify(autoScalingClient, times(0)).updateAutoScalingGroup(requestWithoutScaleIn); - verify(autoScalingClient, times(1)).updateAutoScalingGroup(requestWithScaleIn); + try (MockedConstruction mockedAmazonAutoScalingClient = Mockito.mockConstruction(AmazonAutoScalingClient.class)) { + final UpdateAutoScalingGroupRequest requestWithoutScaleIn = new UpdateAutoScalingGroupRequest() + .withAutoScalingGroupName(ASG_NAME) + .withMinSize(min).withMaxSize(max) + .withDesiredCapacity(targetCapacity); + final UpdateAutoScalingGroupRequest requestWithScaleIn = new UpdateAutoScalingGroupRequest() + .withAutoScalingGroupName(ASG_NAME) + .withMinSize(min).withMaxSize(max) + .withDesiredCapacity(targetCapacity) + .withNewInstancesProtectedFromScaleIn(Boolean.TRUE); + new AutoScalingGroupFleet().modify(CREDS_ID, REGION, ENDPOINT, ASG_NAME, targetCapacity, min, max); + verify(mockedAmazonAutoScalingClient.constructed().get(0), times(0)).updateAutoScalingGroup(requestWithoutScaleIn); + verify(mockedAmazonAutoScalingClient.constructed().get(0), times(1)).updateAutoScalingGroup(requestWithScaleIn); + } } @Test (expected = IllegalArgumentException.class) public void getFleetStateStatesWithEmptyASGs() throws Exception { - when(Jenkins.get()).thenReturn(jenkins); - when(AWSCredentialsHelper.getCredentials(CREDS_ID, jenkins)).thenReturn(amazonWebServicesCredentials); - PowerMockito.whenNew(AmazonAutoScalingClient.class) - .withArguments(amazonWebServicesCredentials, clientConfiguration) - .thenReturn(autoScalingClient); - - final DescribeAutoScalingGroupsRequest describeAutoScalingGroupsRequest = new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(ASG_NAME); - final DescribeAutoScalingGroupsResult result = new DescribeAutoScalingGroupsResult().withAutoScalingGroups(new ArrayList<>()); - when(autoScalingClient.describeAutoScalingGroups(describeAutoScalingGroupsRequest)).thenReturn(result); - - final FleetStateStats fleetStateStats = new AutoScalingGroupFleet().getState(CREDS_ID, REGION, ENDPOINT, ASG_NAME); + mockedJenkins.when(Jenkins::get).thenReturn(jenkins); + mockedAWSCredentialsHelper.when(() -> AWSCredentialsHelper.getCredentials(CREDS_ID, jenkins)).thenReturn(amazonWebServicesCredentials); + + try (MockedConstruction mockedAmazonAutoScalingClient = Mockito.mockConstruction(AmazonAutoScalingClient.class, (autoScalingClient, context) -> { + final DescribeAutoScalingGroupsRequest describeAutoScalingGroupsRequest = new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(ASG_NAME); + final DescribeAutoScalingGroupsResult result = new DescribeAutoScalingGroupsResult().withAutoScalingGroups(new ArrayList<>()); + when(autoScalingClient.describeAutoScalingGroups(describeAutoScalingGroupsRequest)).thenReturn(result); + })) { + final FleetStateStats fleetStateStats = new AutoScalingGroupFleet().getState(CREDS_ID, REGION, ENDPOINT, ASG_NAME); + } // Empty asg list should have thrown exception fail("Exception not raised"); @@ -210,73 +214,69 @@ public void getFleetStateStatesWithEmptyASGs() throws Exception { @Test public void getFleetStateStates() throws Exception { final int desiredCapacity = 5; - when(Jenkins.get()).thenReturn(jenkins); - when(AWSCredentialsHelper.getCredentials(CREDS_ID, jenkins)).thenReturn(amazonWebServicesCredentials); - PowerMockito.whenNew(AmazonAutoScalingClient.class) - .withArguments(amazonWebServicesCredentials, clientConfiguration) - .thenReturn(autoScalingClient); - - - final DescribeAutoScalingGroupsRequest describeAutoScalingGroupsRequest = new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(ASG_NAME); - final AutoScalingGroup asg = new AutoScalingGroup() - .withAutoScalingGroupName(ASG_NAME) - .withDesiredCapacity(desiredCapacity) - .withInstances(Collections.singleton(new Instance().withInstanceId("i-123"))); - - final DescribeAutoScalingGroupsResult describeAutoScalingGroupsResult = new DescribeAutoScalingGroupsResult().withAutoScalingGroups(asg); - when(autoScalingClient.describeAutoScalingGroups(describeAutoScalingGroupsRequest)).thenReturn(describeAutoScalingGroupsResult); - - final FleetStateStats result = new AutoScalingGroupFleet().getState(CREDS_ID, REGION, ENDPOINT, ASG_NAME); - - assertEquals(desiredCapacity, result.getNumDesired()); - assertEquals(ASG_NAME, result.getFleetId()); - assertEquals(FleetStateStats.State.active(), result.getState()); - assertEquals(1, result.getInstances().size()); + mockedJenkins.when(Jenkins::get).thenReturn(jenkins); + mockedAWSCredentialsHelper.when(() -> AWSCredentialsHelper.getCredentials(CREDS_ID, jenkins)).thenReturn(amazonWebServicesCredentials); + + try (MockedConstruction mockedAmazonAutoScalingClient = Mockito.mockConstruction(AmazonAutoScalingClient.class, (autoScalingClient, context) -> { + final DescribeAutoScalingGroupsRequest describeAutoScalingGroupsRequest = new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(ASG_NAME); + final AutoScalingGroup asg = new AutoScalingGroup() + .withAutoScalingGroupName(ASG_NAME) + .withDesiredCapacity(desiredCapacity) + .withInstances(Collections.singleton(new Instance().withInstanceId("i-123"))); + + final DescribeAutoScalingGroupsResult describeAutoScalingGroupsResult = new DescribeAutoScalingGroupsResult().withAutoScalingGroups(asg); + when(autoScalingClient.describeAutoScalingGroups(describeAutoScalingGroupsRequest)).thenReturn(describeAutoScalingGroupsResult); + })) { + final FleetStateStats result = new AutoScalingGroupFleet().getState(CREDS_ID, REGION, ENDPOINT, ASG_NAME); + + assertEquals(desiredCapacity, result.getNumDesired()); + assertEquals(ASG_NAME, result.getFleetId()); + assertEquals(FleetStateStats.State.active(), result.getState()); + assertEquals(1, result.getInstances().size()); + } } @Test public void getFleetStatesWithASGInstanceWeights() throws Exception { final int desiredCapacity = 5; - when(Jenkins.get()).thenReturn(jenkins); - when(AWSCredentialsHelper.getCredentials(CREDS_ID, jenkins)).thenReturn(amazonWebServicesCredentials); - PowerMockito.whenNew(AmazonAutoScalingClient.class) - .withArguments(amazonWebServicesCredentials, clientConfiguration) - .thenReturn(autoScalingClient); - - - final DescribeAutoScalingGroupsRequest describeAutoScalingGroupsRequest = new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(ASG_NAME); - final AutoScalingGroup asg = new AutoScalingGroup() - .withAutoScalingGroupName(ASG_NAME) - .withDesiredCapacity(desiredCapacity) - .withMixedInstancesPolicy(new MixedInstancesPolicy() - .withLaunchTemplate(new LaunchTemplate() - .withOverrides( - new LaunchTemplateOverrides() - .withInstanceType("t3.small") - .withWeightedCapacity("1"), - new LaunchTemplateOverrides() - .withInstanceType("t3.large") - .withWeightedCapacity("2"), - new LaunchTemplateOverrides() - .withInstanceType("t3.xlarge") - ) - ) - ) - .withInstances(Collections.singleton(new Instance().withInstanceId("i-123"))); - - final DescribeAutoScalingGroupsResult describeAutoScalingGroupsResult = new DescribeAutoScalingGroupsResult().withAutoScalingGroups(asg); - when(autoScalingClient.describeAutoScalingGroups(describeAutoScalingGroupsRequest)).thenReturn(describeAutoScalingGroupsResult); - - final FleetStateStats result = new AutoScalingGroupFleet().getState(CREDS_ID, REGION, ENDPOINT, ASG_NAME); - - final Map expectedWeights = new LinkedHashMap<>(); - expectedWeights.put("t3.small", 1d); - expectedWeights.put("t3.large", 2d); - - assertEquals(desiredCapacity, result.getNumDesired()); - assertEquals(ASG_NAME, result.getFleetId()); - assertEquals(FleetStateStats.State.active(), result.getState()); - assertEquals(1, result.getInstances().size()); - assertEquals(result.getInstanceTypeWeights(), expectedWeights); + mockedJenkins.when(Jenkins::get).thenReturn(jenkins); + mockedAWSCredentialsHelper.when(() -> AWSCredentialsHelper.getCredentials(CREDS_ID, jenkins)).thenReturn(amazonWebServicesCredentials); + + try (MockedConstruction mockedAmazonAutoScalingClient = Mockito.mockConstruction(AmazonAutoScalingClient.class, (autoScalingClient, context) -> { + final DescribeAutoScalingGroupsRequest describeAutoScalingGroupsRequest = new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(ASG_NAME); + final AutoScalingGroup asg = new AutoScalingGroup() + .withAutoScalingGroupName(ASG_NAME) + .withDesiredCapacity(desiredCapacity) + .withMixedInstancesPolicy(new MixedInstancesPolicy() + .withLaunchTemplate(new LaunchTemplate() + .withOverrides( + new LaunchTemplateOverrides() + .withInstanceType("t3.small") + .withWeightedCapacity("1"), + new LaunchTemplateOverrides() + .withInstanceType("t3.large") + .withWeightedCapacity("2"), + new LaunchTemplateOverrides() + .withInstanceType("t3.xlarge") + ) + ) + ) + .withInstances(Collections.singleton(new Instance().withInstanceId("i-123"))); + + final DescribeAutoScalingGroupsResult describeAutoScalingGroupsResult = new DescribeAutoScalingGroupsResult().withAutoScalingGroups(asg); + when(autoScalingClient.describeAutoScalingGroups(describeAutoScalingGroupsRequest)).thenReturn(describeAutoScalingGroupsResult); + })) { + final FleetStateStats result = new AutoScalingGroupFleet().getState(CREDS_ID, REGION, ENDPOINT, ASG_NAME); + + final Map expectedWeights = new LinkedHashMap<>(); + expectedWeights.put("t3.small", 1d); + expectedWeights.put("t3.large", 2d); + + assertEquals(desiredCapacity, result.getNumDesired()); + assertEquals(ASG_NAME, result.getFleetId()); + assertEquals(FleetStateStats.State.active(), result.getState()); + assertEquals(1, result.getInstances().size()); + assertEquals(result.getInstanceTypeWeights(), expectedWeights); + } } } From acd60ae7b0a0c5ced167835c4181b036975c5850 Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Wed, 23 Aug 2023 15:33:09 -0700 Subject: [PATCH 2/2] Fix Javadoc generation --- src/main/java/com/amazon/jenkins/ec2fleet/CloudNanny.java | 2 +- .../amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdater.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/CloudNanny.java b/src/main/java/com/amazon/jenkins/ec2fleet/CloudNanny.java index c70170d7..f3ab23f2 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/CloudNanny.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/CloudNanny.java @@ -32,7 +32,7 @@ public long getRecurrencePeriod() { } /** - *

Exceptions

+ *

Exceptions * This method will be executed by {@link PeriodicWork} inside {@link java.util.concurrent.ScheduledExecutorService} * by default it stops execution if task throws exception, however {@link PeriodicWork} fix that * by catch any exception and just log it, so we safe to throw exception here. diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdater.java b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdater.java index cfef4e9e..7c676ad5 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdater.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdater.java @@ -24,7 +24,7 @@ public long getRecurrencePeriod() { } /** - *

Exceptions

+ *

Exceptions * This method will be executed by {@link PeriodicWork} inside {@link java.util.concurrent.ScheduledExecutorService} * by default it stops execution if task throws exception, however {@link PeriodicWork} fix that * by catch any exception and just log it, so we safe to throw exception here.