This is an automated email from the ASF dual-hosted git repository.

casion pushed a commit to branch dev-1.3.1
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git


The following commit(s) were added to refs/heads/dev-1.3.1 by this push:
     new 11ccae109 feat: linkis-ps-common-lock unit test (#3489)
11ccae109 is described below

commit 11ccae109721904a6285a3ad2eba77fb1d351b10
Author: ruY <[email protected]>
AuthorDate: Thu Sep 22 13:38:58 2022 +0800

    feat: linkis-ps-common-lock unit test (#3489)
---
 .../linkis/publicservice/common/lock/Scan.java     | 26 +++++++++
 .../common/lock/WebApplicationServer.java          | 34 ++++++++++++
 .../publicservice/common/lock/dao/BaseDaoTest.java | 31 +++++++++++
 .../common/lock/dao/CommonLockMapperTest.java      | 61 ++++++++++++++++++++++
 .../service/impl/DefaultCommonLockServiceTest.java | 59 +++++++++++++++++++++
 .../src/test/resources/application.properties      | 61 ++++++++++++++++++++++
 .../src/test/resources/create.sql                  | 32 ++++++++++++
 .../src/test/resources/data.sql                    | 22 ++++++++
 .../src/test/resources/linkis.properties           | 21 ++++++++
 9 files changed, 347 insertions(+)

diff --git 
a/linkis-public-enhancements/linkis-ps-common-lock/src/test/java/org/apache/linkis/publicservice/common/lock/Scan.java
 
b/linkis-public-enhancements/linkis-ps-common-lock/src/test/java/org/apache/linkis/publicservice/common/lock/Scan.java
new file mode 100644
index 000000000..44aac7676
--- /dev/null
+++ 
b/linkis-public-enhancements/linkis-ps-common-lock/src/test/java/org/apache/linkis/publicservice/common/lock/Scan.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.linkis.publicservice.common.lock;
+
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+
+import org.mybatis.spring.annotation.MapperScan;
+
+@EnableAutoConfiguration
+@MapperScan(" org.apache.linkis.publicservice.common.lock")
+public class Scan {}
diff --git 
a/linkis-public-enhancements/linkis-ps-common-lock/src/test/java/org/apache/linkis/publicservice/common/lock/WebApplicationServer.java
 
b/linkis-public-enhancements/linkis-ps-common-lock/src/test/java/org/apache/linkis/publicservice/common/lock/WebApplicationServer.java
new file mode 100644
index 000000000..a5a074273
--- /dev/null
+++ 
b/linkis-public-enhancements/linkis-ps-common-lock/src/test/java/org/apache/linkis/publicservice/common/lock/WebApplicationServer.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.linkis.publicservice.common.lock;
+
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.boot.web.servlet.ServletComponentScan;
+import 
org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
+import org.springframework.context.annotation.ComponentScan;
+
+@EnableAutoConfiguration
+@ServletComponentScan
+@ComponentScan
+public class WebApplicationServer extends SpringBootServletInitializer {
+
+  public static void main(String[] args) {
+    new SpringApplicationBuilder(WebApplicationServer.class).run(args);
+  }
+}
diff --git 
a/linkis-public-enhancements/linkis-ps-common-lock/src/test/java/org/apache/linkis/publicservice/common/lock/dao/BaseDaoTest.java
 
b/linkis-public-enhancements/linkis-ps-common-lock/src/test/java/org/apache/linkis/publicservice/common/lock/dao/BaseDaoTest.java
new file mode 100644
index 000000000..b2522d6e0
--- /dev/null
+++ 
b/linkis-public-enhancements/linkis-ps-common-lock/src/test/java/org/apache/linkis/publicservice/common/lock/dao/BaseDaoTest.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.linkis.publicservice.common.lock.dao;
+
+import org.apache.linkis.publicservice.common.lock.Scan;
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.Rollback;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+import org.springframework.transaction.annotation.Transactional;
+
+@SpringBootTest(classes = Scan.class)
+@Transactional
+@Rollback()
+@EnableTransactionManagement
+public abstract class BaseDaoTest {}
diff --git 
a/linkis-public-enhancements/linkis-ps-common-lock/src/test/java/org/apache/linkis/publicservice/common/lock/dao/CommonLockMapperTest.java
 
b/linkis-public-enhancements/linkis-ps-common-lock/src/test/java/org/apache/linkis/publicservice/common/lock/dao/CommonLockMapperTest.java
new file mode 100644
index 000000000..a1b2b1c51
--- /dev/null
+++ 
b/linkis-public-enhancements/linkis-ps-common-lock/src/test/java/org/apache/linkis/publicservice/common/lock/dao/CommonLockMapperTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.linkis.publicservice.common.lock.dao;
+
+import org.apache.linkis.publicservice.common.lock.entity.CommonLock;
+
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.List;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+public class CommonLockMapperTest extends BaseDaoTest {
+
+  @Autowired private CommonLockMapper commonLockMapper;
+
+  @Test
+  @DisplayName("getAll")
+  public void getAllTest() {
+
+    List<CommonLock> locks = commonLockMapper.getAll();
+    Assertions.assertTrue(locks.size() == 1);
+  }
+
+  @Test
+  @DisplayName("unlockTest")
+  public void unlockTest() {
+    String lockObject = "hadoop-warehouse";
+    commonLockMapper.unlock(lockObject);
+
+    List<CommonLock> locks = commonLockMapper.getAll();
+    Assertions.assertTrue(locks.size() == 0);
+  }
+
+  @Test
+  @DisplayName("lockTest")
+  public void lockTest() {
+    String lockObject = "hadoop-warehouse2";
+    Long timeOut = 10000L;
+    commonLockMapper.lock(lockObject, timeOut);
+    List<CommonLock> locks = commonLockMapper.getAll();
+    Assertions.assertTrue(locks.size() == 2);
+  }
+}
diff --git 
a/linkis-public-enhancements/linkis-ps-common-lock/src/test/java/org/apache/linkis/publicservice/common/lock/service/impl/DefaultCommonLockServiceTest.java
 
b/linkis-public-enhancements/linkis-ps-common-lock/src/test/java/org/apache/linkis/publicservice/common/lock/service/impl/DefaultCommonLockServiceTest.java
new file mode 100644
index 000000000..1cc389d8e
--- /dev/null
+++ 
b/linkis-public-enhancements/linkis-ps-common-lock/src/test/java/org/apache/linkis/publicservice/common/lock/service/impl/DefaultCommonLockServiceTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.linkis.publicservice.common.lock.service.impl;
+
+import org.apache.linkis.publicservice.common.lock.dao.CommonLockMapper;
+import org.apache.linkis.publicservice.common.lock.entity.CommonLock;
+
+import java.util.List;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+@ExtendWith(MockitoExtension.class)
+public class DefaultCommonLockServiceTest {
+
+  @InjectMocks private DefaultCommonLockService commonLockService;
+
+  @Mock private CommonLockMapper commonLockMapper;
+
+  @Test
+  @DisplayName("lockTest")
+  public void lockTest() {
+
+    CommonLock commonLock = new CommonLock();
+    commonLock.setLockObject("hadoops");
+    Long timeOut = 10000L;
+    Boolean lock = commonLockService.lock(commonLock, timeOut);
+
+    Assertions.assertTrue(lock.booleanValue());
+  }
+
+  @Test
+  @DisplayName("getAllTest")
+  public void getAllTest() {
+
+    List<CommonLock> locks = commonLockService.getAll();
+    Assertions.assertTrue(locks.size() == 0);
+  }
+}
diff --git 
a/linkis-public-enhancements/linkis-ps-common-lock/src/test/resources/application.properties
 
b/linkis-public-enhancements/linkis-ps-common-lock/src/test/resources/application.properties
new file mode 100644
index 000000000..df58ee9f8
--- /dev/null
+++ 
b/linkis-public-enhancements/linkis-ps-common-lock/src/test/resources/application.properties
@@ -0,0 +1,61 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+#wds.linkis.test.mode=true
+wds.linkis.server.version=v1
+
+#test
+wds.linkis.test.mode=true
+wds.linkis.test.user=hadoop
+
+
+##Linkis governance station administrators
+wds.linkis.governance.station.admin=hadoop
+wds.linkis.gateway.conf.publicservice.list=query,jobhistory,application,configuration,filesystem,udf,variable,microservice,errorcode,bml,datasource
+#
+
+#logging.level.root=debug
+#logging.file=./test.log
+#debug=true
+
+spring.datasource.driver-class-name=org.h2.Driver
+spring.datasource.url=jdbc:h2:mem:test;MODE=MySQL;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=true
+spring.datasource.schema=classpath:create.sql
+spring.datasource.data=classpath:data.sql
+spring.datasource.username=sa
+spring.datasource.password=
+spring.datasource.hikari.connection-test-query=select 1
+spring.datasource.hikari.minimum-idle=5
+spring.datasource.hikari.auto-commit=true
+spring.datasource.hikari.validation-timeout=3000
+spring.datasource.hikari.pool-name=linkis-test
+spring.datasource.hikari.maximum-pool-size=50
+spring.datasource.hikari.connection-timeout=30000
+spring.datasource.hikari.idle-timeout=600000
+spring.datasource.hikari.leak-detection-threshold=0
+spring.datasource.hikari.initialization-fail-timeout=1
+
+spring.main.web-application-type=servlet
+server.port=1234
+spring.h2.console.enabled=true
+
+#disable eureka discovery client
+spring.cloud.service-registry.auto-registration.enabled=false
+eureka.client.enabled=false
+eureka.client.serviceUrl.registerWithEureka=false
+
+mybatis-plus.mapper-locations=classpath:org/apache/linkis/variable/dao/impl/*.xml
+mybatis-plus.type-aliases-package=org.apache.linkis.variable.entity
+mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
\ No newline at end of file
diff --git 
a/linkis-public-enhancements/linkis-ps-common-lock/src/test/resources/create.sql
 
b/linkis-public-enhancements/linkis-ps-common-lock/src/test/resources/create.sql
new file mode 100644
index 000000000..2d9437a75
--- /dev/null
+++ 
b/linkis-public-enhancements/linkis-ps-common-lock/src/test/resources/create.sql
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+*/
+SET FOREIGN_KEY_CHECKS = 0;
+
+-- ----------------------------
+-- Table structure for linkis_ps_variable_key_user
+-- ----------------------------
+DROP TABLE IF EXISTS `linkis_ps_common_lock`;
+CREATE TABLE `linkis_ps_common_lock` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `lock_object` varchar(255)  DEFAULT NULL,
+  `time_out` longtext ,
+  `update_time` datetime DEFAULT CURRENT_TIMESTAMP,
+  `create_time` datetime DEFAULT CURRENT_TIMESTAMP,
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `lock_object` (`lock_object`)
+) ;
+
diff --git 
a/linkis-public-enhancements/linkis-ps-common-lock/src/test/resources/data.sql 
b/linkis-public-enhancements/linkis-ps-common-lock/src/test/resources/data.sql
new file mode 100644
index 000000000..0df1d1fe8
--- /dev/null
+++ 
b/linkis-public-enhancements/linkis-ps-common-lock/src/test/resources/data.sql
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+*/
+
+DELETE FROM linkis_ps_common_lock;
+
+insert into 
linkis_ps_common_lock(`id`,`lock_object`,`time_out`,`update_time`,`create_time`)
 values (1,'hadoop-warehouse',1000000,now(),now());
+
+
diff --git 
a/linkis-public-enhancements/linkis-ps-common-lock/src/test/resources/linkis.properties
 
b/linkis-public-enhancements/linkis-ps-common-lock/src/test/resources/linkis.properties
new file mode 100644
index 000000000..1c575edc5
--- /dev/null
+++ 
b/linkis-public-enhancements/linkis-ps-common-lock/src/test/resources/linkis.properties
@@ -0,0 +1,21 @@
+# 
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+#wds.linkis.test.mode=true
+wds.linkis.server.version=v1
+
+#test
+wds.linkis.test.mode=true
+wds.linkis.test.user=hadoop
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to