+ bluePrintRuntimeService.resolvePropertyAssignments(any(), any(), any())
+ } returns mutableMapOf(
+ "key" to "abc-123-def-456".asJsonType(),
+ "acquireTimeout" to implementation.lock!!.acquireTimeout
+ )
+
+ val component: AbstractComponentFunction = SampleComponent()
+ component.bluePrintRuntimeService = bluePrintRuntimeService
+ component.bluePrintClusterService = blueprintClusterService
+
+ runBlocking {
+ component.prepareRequestNB(getMockedInput(bluePrintRuntimeService))
+ }
+
+ val resolvedLock = component.implementation.lock!!
+
+ assertEquals("abc-123-def-456", resolvedLock.key.textValue())
+ // default value
+ assertEquals(180, resolvedLock.acquireTimeout.intValue())
+ }
+
+ @Test(expected = Exception::class)
+ fun `prepareRequestNB should throw exception if it fails to resolve lock key`() {
+ every {
+ blueprintContext.nodeTemplateOperationImplementation(any(), any(), any())
+ } returns Implementation().apply { this.lock = LockAssignment() }
+
+ every {
+ bluePrintRuntimeService.resolvePropertyAssignments(any(), any(), any())
+ } returns mutableMapOf("key" to "".asJsonType(),
+ "acquireTimeout" to Integer(360).asJsonType())
+
+ val component: AbstractComponentFunction = SampleComponent()
+ component.bluePrintRuntimeService = bluePrintRuntimeService
+ component.bluePrintClusterService = blueprintClusterService
+
+ runBlocking {
+ component.prepareRequestNB(getMockedInput(bluePrintRuntimeService))
+ }
+ }
+
+ @Test
+ fun `applyNB - when lock is present use ClusterLock`() {
+
+ val lockName = "testing-lock"
+
+ every {
+ blueprintContext.nodeTemplateOperationImplementation(any(), any(), any())
+ } returns Implementation().apply {
+ this.lock = LockAssignment().apply { this.key = lockName.asJsonType() }
+ }
+
+ every {
+ bluePrintRuntimeService.resolvePropertyAssignments(any(), any(), any())
+ } returns mutableMapOf("key" to lockName.asJsonType(),
+ "acquireTimeout" to Integer(180).asJsonType())
+
+ val clusterLock: ClusterLock = mockk()
+
+ every { clusterLock.name() } returns lockName
+ every { runBlocking { clusterLock.tryLock(any()) } } returns true
+ every { runBlocking { clusterLock.unLock() } } returns Unit
+
+ every {
+ runBlocking { blueprintClusterService.clusterLock(any()) }
+ } returns clusterLock
+
+ val component: AbstractComponentFunction = SampleComponent()
+ component.bluePrintRuntimeService = bluePrintRuntimeService
+ component.bluePrintClusterService = blueprintClusterService
+
+ runBlocking {
+ component.applyNB(getMockedInput(bluePrintRuntimeService))
+ }
+
+ verify {
+ runBlocking { blueprintClusterService.clusterLock("$lockName@$CDS_LOCK_GROUP") }
+ }
+ verify { runBlocking { clusterLock.unLock() } }