+++ /dev/null
-/*******************************************************************************
- * Copyright 2019 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *******************************************************************************/
-package servicemgr_test
-
-import (
- "strings"
- "testing"
-)
-
-const (
- serviceName = "ls"
- serviceName2 = "main2"
-)
-
-func assertEqualStr(t *testing.T, a, b string) {
- t.Helper()
- if strings.Compare(a, b) != 0 {
- t.Errorf("%s != %s", a, b)
- }
-}
-
-func retError(t *testing.T, err error) {
- t.Helper()
-
- if err != nil {
- t.Error(err.Error())
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright 2019 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *******************************************************************************/
-package servicemgr
-
-import "errors"
-
-const (
- // ConstKeyServiceID is key of service id
- ConstKeyServiceID = "ServiceID"
-
- // ConstKeyServiceName is key of service name
- ConstKeyServiceName = "ServiceName"
-
- // ConstKeyNotiChan is key of notification channel
- ConstKeyNotiChan = "NotiChan"
-
- // ConstKeyStatus is key of status
- ConstKeyStatus = "Status"
-
- // ConstKeyUserArgs is key of user argument
- ConstKeyUserArgs = "UserArgs"
-
- // ConstKeyNotiTargetURL is key of notification target URL
- ConstKeyNotiTargetURL = "NotificationTargetURL"
-
- // ConstServiceStatusFailed is service status is failed
- ConstServiceStatusFailed = "Failed"
-
- // ConstServiceStatusStarted is service status is started
- ConstServiceStatusStarted = "Started"
-
- // ConstServiceStatusFinished is service status is finished
- ConstServiceStatusFinished = "Finished"
-
- // ConstServiceFound is service status is found
- ConstServiceFound = "Found"
-
- // ConstServiceNotFound is service status is not found
- ConstServiceNotFound = "NotFound"
-
- // ConstServiceExecuteURI is URI for creating & executing service
- ConstServiceExecuteURI = "/api/v1/servicemgr/services"
-
- // ConstServiceStatusNotiURI is URI for notification status of service
- ConstServiceStatusNotiURI = "/api/v1/servicemgr/services/notification/"
-)
-
-var (
- // ErrInvalidService is for error type of invalid service
- ErrInvalidService = errors.New("It is Invalid Service")
-
- // ServiceMap is service map
- ServiceMap ConcurrentMap
-
- // ServiceIdx is for unique service ID (process id)
- ServiceIdx uint64
-)
+package servicemgr
+
/*******************************************************************************
* Copyright 2019 Samsung Electronics All Rights Reserved.
*
* limitations under the License.
*
*******************************************************************************/
-package servicemgr
import (
"sync/atomic"
+package servicemgr
+
/*******************************************************************************
* Copyright 2019 Samsung Electronics All Rights Reserved.
*
* limitations under the License.
*
*******************************************************************************/
-package servicemgr
-import "sync"
+import (
+ "errors"
+ "sync"
+)
+
+const (
+ // ConstKeyServiceID is key of service id
+ ConstKeyServiceID = "ServiceID"
+
+ // ConstKeyServiceName is key of service name
+ ConstKeyServiceName = "ServiceName"
+
+ // ConstKeyNotiChan is key of notification channel
+ ConstKeyNotiChan = "NotiChan"
+
+ // ConstKeyStatus is key of status
+ ConstKeyStatus = "Status"
+
+ // ConstKeyUserArgs is key of user argument
+ ConstKeyUserArgs = "UserArgs"
+
+ // ConstKeyNotiTargetURL is key of notification target URL
+ ConstKeyNotiTargetURL = "NotificationTargetURL"
+
+ // ConstServiceStatusFailed is service status is failed
+ ConstServiceStatusFailed = "Failed"
+
+ // ConstServiceStatusStarted is service status is started
+ ConstServiceStatusStarted = "Started"
+
+ // ConstServiceStatusFinished is service status is finished
+ ConstServiceStatusFinished = "Finished"
+
+ // ConstServiceFound is service status is found
+ ConstServiceFound = "Found"
+
+ // ConstServiceNotFound is service status is not found
+ ConstServiceNotFound = "NotFound"
+)
+
+var (
+ logPrefix = "servicemgr"
+
+ // ErrInvalidService is for error type of invalid service
+ ErrInvalidService = errors.New("It is Invalid Service")
+
+ // ServiceMap is service map
+ ServiceMap ConcurrentMap
-var logPrefix = "servicemgr"
+ // ServiceIdx is for unique service ID (process id)
+ ServiceIdx uint64
+)
// ServiceParam structrue
type ServiceParam struct {
+++ /dev/null
-/*******************************************************************************
- * Copyright 2019 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *******************************************************************************/
-package servicemgr_test
-
-import (
- "servicemgr"
- "strings"
- "testing"
-)
-
-func TestMapSetGet(t *testing.T) {
- servicemgr.Init()
- servicemgr.ServiceMap.Set(uint64(1), serviceName)
-
- str, _ := servicemgr.ServiceMap.Get(uint64(1))
- assertEqualStr(t, str.(string), serviceName)
-}
-
-func TestMapRemove(t *testing.T) {
- servicemgr.Init()
- servicemgr.ServiceMap.Set(uint64(1), serviceName)
-
- servicemgr.ServiceMap.Remove(uint64(1))
-
- exist, _ := servicemgr.ServiceMap.Get(uint64(1))
- if exist != nil {
- t.Error("ConcurrentMap Remove API is failed")
- }
-}
-
-func TestMapModify(t *testing.T) {
- servicemgr.Init()
- servicemgr.ServiceMap.Set(uint64(1), serviceName)
- servicemgr.ServiceMap.Set(uint64(1), serviceName2)
-
- str, _ := servicemgr.ServiceMap.Get(uint64(1))
- assertEqualStr(t, str.(string), serviceName2)
-}
-
-func TestMapIter(t *testing.T) {
- servicemgr.Init()
- servicemgr.ServiceMap.Set(uint64(1), serviceName)
- servicemgr.ServiceMap.Set(uint64(2), serviceName2)
-
- mapItem := servicemgr.ServiceMap.Iter()
- compareStr := make([]string, 10)
- idx := 0
-
- for {
- msg := <-mapItem
-
- t.Log(msg.Key, msg.Value)
-
- if msg.Value == nil && msg.Key == 0 {
- break
- } else {
- compareStr[idx] = msg.Value.(string)
- }
- }
-
- for _, str := range compareStr {
- if len(str) == 0 {
- break
- }
-
- if strings.Compare(str, serviceName) == 0 || strings.Compare(str, serviceName2) == 0 {
- continue
- } else {
- t.Fail()
- }
- }
-}
--- /dev/null
+package servicemgr_test
+
+/*******************************************************************************
+ * Copyright 2019 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *******************************************************************************/
+
+import (
+ "servicemgr"
+ "strings"
+ "testing"
+)
+
+func TestMapSetGet(t *testing.T) {
+ servicemgr.Init()
+ servicemgr.ServiceMap.Set(uint64(1), serviceName)
+
+ str, _ := servicemgr.ServiceMap.Get(uint64(1))
+ assertEqualStr(t, str.(string), serviceName)
+}
+
+func TestMapRemove(t *testing.T) {
+ servicemgr.Init()
+ servicemgr.ServiceMap.Set(uint64(1), serviceName)
+
+ servicemgr.ServiceMap.Remove(uint64(1))
+
+ exist, _ := servicemgr.ServiceMap.Get(uint64(1))
+ if exist != nil {
+ t.Error("ConcurrentMap Remove API is failed")
+ }
+}
+
+func TestMapModify(t *testing.T) {
+ servicemgr.Init()
+ servicemgr.ServiceMap.Set(uint64(1), serviceName)
+ servicemgr.ServiceMap.Set(uint64(1), serviceName2)
+
+ str, _ := servicemgr.ServiceMap.Get(uint64(1))
+ assertEqualStr(t, str.(string), serviceName2)
+}
+
+func TestMapIter(t *testing.T) {
+ servicemgr.Init()
+ servicemgr.ServiceMap.Set(uint64(1), serviceName)
+ servicemgr.ServiceMap.Set(uint64(2), serviceName2)
+
+ mapItem := servicemgr.ServiceMap.Iter()
+ compareStr := make([]string, 10)
+ idx := 0
+
+ for {
+ msg := <-mapItem
+
+ t.Log(msg.Key, msg.Value)
+
+ if msg.Value == nil && msg.Key == 0 {
+ break
+ } else {
+ compareStr[idx] = msg.Value.(string)
+ }
+ }
+
+ for _, str := range compareStr {
+ if len(str) == 0 {
+ break
+ }
+
+ if strings.Compare(str, serviceName) == 0 || strings.Compare(str, serviceName2) == 0 {
+ continue
+ } else {
+ t.Fail()
+ }
+ }
+}