@@ -51,8 +51,6 @@ public class KubernetesAgentInstancesTest {
51
51
@ Mock
52
52
PluginRequest mockPluginRequest ;
53
53
54
- @ Mock
55
- PodOperationsImpl mockPods ;
56
54
private HashMap <String , String > testProperties ;
57
55
58
56
@ Before
@@ -61,11 +59,13 @@ public void setUp() throws Exception {
61
59
testProperties = new HashMap <>();
62
60
when (mockCreateAgentRequest .properties ()).thenReturn (testProperties );
63
61
when (factory .kubernetes (mockPluginSettings )).thenReturn (mockKubernetesClient );
62
+ JobIdentifier jobId = new JobIdentifier ("test" , 1L , "Test pipeline" , "test name" , "1" , "test job" , 100L );
63
+ when (mockCreateAgentRequest .jobIdentifier ()).thenReturn (jobId );
64
64
}
65
65
66
66
@ Test
67
67
public void shouldCreateKubernetesPodUsingPodYamlAndCacheCreatedInstance () throws Exception {
68
- KubernetesInstance kubernetesInstance = new KubernetesInstance (new DateTime (), "test" , "test-agent" , new HashMap <>(), null );
68
+ KubernetesInstance kubernetesInstance = new KubernetesInstance (new DateTime (), "test" , "test-agent" , new HashMap <>(), 100L );
69
69
when (mockKubernetesInstanceFactory .create (mockCreateAgentRequest , mockPluginSettings , mockKubernetesClient , mockPluginRequest , true )).
70
70
thenReturn (kubernetesInstance );
71
71
@@ -78,12 +78,30 @@ public void shouldCreateKubernetesPodUsingPodYamlAndCacheCreatedInstance() throw
78
78
79
79
@ Test
80
80
public void shouldCreateKubernetesPodAndCacheCreatedInstance () throws Exception {
81
- KubernetesInstance kubernetesInstance = new KubernetesInstance (new DateTime (), "test" , "test-agent" , new HashMap <>(), null );
81
+ KubernetesInstance kubernetesInstance = new KubernetesInstance (new DateTime (), "test" , "test-agent" , new HashMap <>(), 100L );
82
82
when (mockKubernetesInstanceFactory .create (mockCreateAgentRequest , mockPluginSettings , mockKubernetesClient , mockPluginRequest , false )).
83
83
thenReturn (kubernetesInstance );
84
84
testProperties .put ("SpecifiedUsingPodConfiguration" , "false" );
85
85
KubernetesAgentInstances agentInstances = new KubernetesAgentInstances (factory , mockKubernetesInstanceFactory );
86
86
KubernetesInstance instance = agentInstances .create (mockCreateAgentRequest , mockPluginSettings , mockPluginRequest );
87
87
assertTrue (agentInstances .instanceExists (instance ));
88
88
}
89
+
90
+ @ Test
91
+ public void shouldNotCreatePodWhenOutstandingRequestsExistForJobs () throws Exception {
92
+ KubernetesInstance kubernetesInstance = new KubernetesInstance (new DateTime (), "test" , "test-agent" , new HashMap <>(), 100L );
93
+ when (mockKubernetesInstanceFactory .create (mockCreateAgentRequest , mockPluginSettings , mockKubernetesClient , mockPluginRequest , false )).
94
+ thenReturn (kubernetesInstance );
95
+ testProperties .put ("SpecifiedUsingPodConfiguration" , "false" );
96
+
97
+ KubernetesAgentInstances agentInstances = new KubernetesAgentInstances (factory , mockKubernetesInstanceFactory );
98
+ JobIdentifier jobId = new JobIdentifier ("test" , 1L , "Test pipeline" , "test name" , "1" , "test job" , 100L );
99
+ when (mockCreateAgentRequest .jobIdentifier ()).thenReturn (jobId );
100
+ agentInstances .create (mockCreateAgentRequest , mockPluginSettings , mockPluginRequest );
101
+ verify (mockKubernetesInstanceFactory , times (1 )).create (any (), any (), any (), any (), any ());
102
+ reset (mockKubernetesInstanceFactory );
103
+
104
+ agentInstances .create (mockCreateAgentRequest , mockPluginSettings , mockPluginRequest );
105
+ verify (mockKubernetesInstanceFactory , times (0 )).create (any (), any (), any (), any (), any ());
106
+ }
89
107
}
0 commit comments