2 * Copyright © 2018-2019 AT&T Intellectual Property.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.cds.blueprintsprocessor.atomix
19 import com.fasterxml.jackson.databind.JsonNode
20 import kotlinx.coroutines.Dispatchers
21 import kotlinx.coroutines.async
22 import kotlinx.coroutines.awaitAll
23 import kotlinx.coroutines.delay
24 import kotlinx.coroutines.runBlocking
25 import org.junit.Before
27 import org.onap.ccsdk.cds.blueprintsprocessor.atomix.service.AtomixBluePrintClusterService
28 import org.onap.ccsdk.cds.blueprintsprocessor.atomix.utils.AtomixLibUtils
29 import org.onap.ccsdk.cds.blueprintsprocessor.core.service.ClusterInfo
30 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
31 import org.onap.ccsdk.cds.controllerblueprints.core.deleteNBDir
32 import org.onap.ccsdk.cds.controllerblueprints.core.logger
33 import kotlin.test.assertNotNull
35 class AtomixBluePrintClusterServiceTest {
36 val log = logger(AtomixBluePrintClusterServiceTest::class)
41 deleteNBDir("target/cluster")
45 /** Testing two cluster with distributed map store creation, This is time consuming test casetake around 10s **/
47 fun testClusterJoin() {
49 val members = arrayListOf("node-5679", "node-5680")
50 val deferred = arrayListOf(5679, 5680).map { port ->
51 async(Dispatchers.IO) {
52 val nodeId = "node-$port"
53 log.info("********** Starting node($nodeId) on port($port)")
54 val clusterInfo = ClusterInfo(
55 id = "test-cluster", nodeId = nodeId,
56 clusterMembers = members, nodeAddress = "localhost:$port", storagePath = "target/cluster"
58 val atomixClusterService = AtomixBluePrintClusterService()
59 atomixClusterService.startCluster(clusterInfo)
60 atomixClusterService.atomix
63 val atomix = deferred.awaitAll()
64 /** Test Distributed store creation */
65 repeat(2) { storeId ->
66 val store = AtomixLibUtils.distributedMapStore<JsonNode>(atomix.get(0), "blueprint-runtime-$storeId")
67 assertNotNull(store, "failed to get store")
68 val store1 = AtomixLibUtils.distributedMapStore<JsonNode>(atomix.get(1), "blueprint-runtime-$storeId")
70 log.info("Received map event : $it")
73 store["key-$storeId-$it"] = "value-$it".asJsonPrimitive()