-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* add test case for [linkis-scheduler] #1914 * add test case for [linkis-scheduler] #1914 * add test case for [linkis-scheduler] #1914 Co-authored-by: “e <[email protected]>
- Loading branch information
1 parent
d57abbc
commit 32aac24
Showing
17 changed files
with
630 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...cheduler/src/test/scala/org/apache/linkis/scheduler/conf/SchedulerConfigurationTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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.scheduler.conf | ||
|
||
import org.apache.linkis.common.conf.{CommonVars, TimeType} | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
|
||
class SchedulerConfigurationTest { | ||
|
||
@Test | ||
def testSchedulerConfiguration: Unit = { | ||
|
||
val fifoConsumerAutoClearEnabled = CommonVars("wds.linkis.fifo.consumer.auto.clear.enabled", true) | ||
assertEquals(SchedulerConfiguration.FIFO_CONSUMER_AUTO_CLEAR_ENABLED, fifoConsumerAutoClearEnabled) | ||
val fifoConsumerMaxIdleTime = CommonVars("wds.linkis.fifo.consumer.max.idle.time", new TimeType("1h")).getValue.toLong | ||
assertEquals(SchedulerConfiguration.FIFO_CONSUMER_MAX_IDLE_TIME, fifoConsumerMaxIdleTime) | ||
assertEquals(SchedulerConfiguration.FIFO_CONSUMER_IDLE_SCAN_INTERVAL.getValue.toLong, 7200000) | ||
val fifoConsumerIdleScanInitTime = CommonVars("wds.linkis.fifo.consumer.idle.scan.init.time", new TimeType("1s")).getValue.toLong | ||
assertEquals(SchedulerConfiguration.FIFO_CONSUMER_IDLE_SCAN_INIT_TIME.getValue.toLong, fifoConsumerIdleScanInitTime) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...mons/linkis-scheduler/src/test/scala/org/apache/linkis/scheduler/event/LogEventTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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.scheduler.event | ||
|
||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
|
||
class LogEventTest { | ||
@Test | ||
def testLogEvent: Unit = { | ||
val logEvent = LogEvent | ||
|
||
assertEquals(2, logEvent.write) | ||
assertEquals(1, logEvent.read) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...er/src/test/scala/org/apache/linkis/scheduler/exception/LinkisJobRetryExceptionTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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.scheduler.exception | ||
|
||
|
||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
|
||
class LinkisJobRetryExceptionTest { | ||
|
||
@Test | ||
def testLinkisJobRetryException: Unit = { | ||
val des = "testLinkisJobRetryExceptionTest" | ||
val localIp = "127.0.0.1"; | ||
val linkisJobRetryException = new LinkisJobRetryException(des); | ||
linkisJobRetryException.setIp(localIp) | ||
assertEquals(des, linkisJobRetryException.getDesc) | ||
assertEquals(25000, linkisJobRetryException.getErrCode) | ||
assertEquals(localIp, linkisJobRetryException.getIp) | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...er/src/test/scala/org/apache/linkis/scheduler/exception/SchedulerErrorExceptionTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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.scheduler.exception | ||
|
||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
|
||
class SchedulerErrorExceptionTest { | ||
|
||
@Test | ||
def testSchedulerErrorException: Unit = { | ||
val des = "testSchedulerErrorExceptionTest" | ||
val localIp = "127.0.0.1"; | ||
val errorCode = 25000 | ||
val schedulerErrorException = new SchedulerErrorException(errorCode, des); | ||
schedulerErrorException.setIp(localIp) | ||
assertEquals(des, schedulerErrorException.getDesc) | ||
assertEquals(25000, schedulerErrorException.getErrCode) | ||
assertEquals(localIp, schedulerErrorException.getIp) | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...est/scala/org/apache/linkis/scheduler/exception/WaitForNextAskExecutorExceptionTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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.scheduler.exception | ||
|
||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
|
||
class WaitForNextAskExecutorExceptionTest { | ||
|
||
@Test | ||
def testWaitForNextAskExecutorException: Unit = { | ||
val des = "testWaitForNextAskExecutorExceptionTest" | ||
val localIp = "127.0.0.1"; | ||
val errorCode = 12111 | ||
val waitForNextAskExecutorException = new WaitForNextAskExecutorException(des); | ||
waitForNextAskExecutorException.setIp(localIp) | ||
assertEquals(des, waitForNextAskExecutorException.getDesc) | ||
assertEquals(errorCode, waitForNextAskExecutorException.getErrCode) | ||
assertEquals(localIp, waitForNextAskExecutorException.getIp) | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...inkis-scheduler/src/test/scala/org/apache/linkis/scheduler/future/BDPFutureTaskTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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.scheduler.future | ||
|
||
import org.apache.linkis.common.utils.Utils | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
|
||
import java.util.concurrent.{ExecutorService, Future} | ||
|
||
class BDPFutureTaskTest { | ||
private var future: Future[_] = _ | ||
private var bdpFutureTask: BDPFuture = _ | ||
@Test | ||
def testBDPFutureTask: Unit = { | ||
val executeService: ExecutorService = Utils.newCachedThreadPool(1, "test" + "-ThreadPool-", true) | ||
|
||
val runnable = new Thread(new Runnable { | ||
override def run(): Unit = Thread.sleep(1000) | ||
}) | ||
|
||
future = executeService.submit(runnable) | ||
bdpFutureTask = new BDPFutureTask(future) | ||
if (runnable.isAlive) { | ||
assertEquals(false, runnable.isInterrupted) | ||
bdpFutureTask.cancel() | ||
assertEquals(true, runnable.isInterrupted) | ||
} | ||
|
||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
.../src/test/scala/org/apache/linkis/scheduler/queue/fifoqueue/FIFOConsumerManagerTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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.scheduler.queue.fifoqueue | ||
|
||
import org.junit.jupiter.api.Assertions.{assertFalse, assertNotNull, assertNull, assertTrue} | ||
import org.junit.jupiter.api.Test | ||
|
||
class FIFOConsumerManagerTest { | ||
@Test | ||
def testSetSchedulerContext: Unit = { | ||
val schedulerContext = new FIFOSchedulerContextImpl(100) | ||
val consumerManager = new FIFOConsumerManager | ||
consumerManager.setSchedulerContext(schedulerContext) | ||
assertNotNull(consumerManager.listConsumers()) | ||
} | ||
@Test | ||
def testListConsumers: Unit = { | ||
val schedulerContext = new FIFOSchedulerContextImpl(100) | ||
val consumerManager = new FIFOConsumerManager | ||
assertNull(consumerManager.listConsumers()(0)) | ||
consumerManager.setSchedulerContext(schedulerContext) | ||
assertNotNull(consumerManager.listConsumers()(0)) | ||
} | ||
@Test | ||
def testShutdown: Unit = { | ||
val schedulerContext = new FIFOSchedulerContextImpl(100) | ||
val consumerManager = new FIFOConsumerManager | ||
consumerManager.setSchedulerContext(schedulerContext) | ||
assertFalse(consumerManager.listConsumers()(0).terminate) | ||
try { | ||
try | ||
consumerManager.shutdown() | ||
} catch { | ||
case e => e.printStackTrace | ||
} | ||
assertTrue(consumerManager.listConsumers()(0).terminate) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ler/src/test/scala/org/apache/linkis/scheduler/queue/fifoqueue/FIFOGroupFactoryTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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.scheduler.queue.fifoqueue | ||
|
||
import org.junit.jupiter.api.Assertions.{assertEquals, assertNotNull} | ||
import org.junit.jupiter.api.Test | ||
|
||
class FIFOGroupFactoryTest { | ||
@Test | ||
def testGroupFactory: Unit = { | ||
val schedulerContext = new FIFOSchedulerContextImpl(100) | ||
val groupFactory = new FIFOGroupFactory() | ||
groupFactory.setDefaultMaxRunningJobs(10) | ||
schedulerContext.setGroupFactory(groupFactory) | ||
groupFactory.setDefaultMaxAskExecutorTimes(100L) | ||
assertEquals(10, groupFactory.getDefaultMaxRunningJobs) | ||
assertEquals(100L, groupFactory.getDefaultMaxAskExecutorTimes) | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...-scheduler/src/test/scala/org/apache/linkis/scheduler/queue/fifoqueue/FIFOGroupTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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.scheduler.queue.fifoqueue | ||
|
||
import org.apache.linkis.scheduler.queue.GroupStatus | ||
import org.junit.jupiter.api.Assertions.{assertEquals, assertNotNull} | ||
import org.junit.jupiter.api.Test | ||
|
||
class FIFOGroupTest { | ||
@Test | ||
def testFIFOGroup: Unit = { | ||
val schedulerContext = new FIFOSchedulerContextImpl(100) | ||
val group = schedulerContext.getOrCreateGroupFactory | ||
.getOrCreateGroup(null).asInstanceOf[FIFOGroup] | ||
group.setMaxAskInterval(10) | ||
group.setMinAskInterval(8) | ||
group.setStatus(GroupStatus.USING) | ||
group.setMaxRunningJobs(10) | ||
group.setMaxAskExecutorTimes(100L) | ||
assertEquals(10, group.getMaxAskInterval) | ||
assertEquals(8, group.getMinAskInterval) | ||
assertEquals(GroupStatus.USING, group.getStatus) | ||
assertEquals(10, group.getMaxRunningJobs) | ||
assertEquals(100L, group.getMaxAskExecutorTimes) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...test/scala/org/apache/linkis/scheduler/queue/fifoqueue/FIFOSchedulerContextImplTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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.scheduler.queue.fifoqueue | ||
|
||
import org.junit.jupiter.api.Assertions.{assertEquals, assertNotNull} | ||
import org.junit.jupiter.api.Test | ||
|
||
class FIFOSchedulerContextImplTest { | ||
@Test | ||
def testGetOrCreateGroupFactory: Unit = { | ||
val schedulerContext = new FIFOSchedulerContextImpl(100) | ||
val group = schedulerContext.getOrCreateGroupFactory.getOrCreateGroup(null) | ||
assertNotNull(group) | ||
} | ||
@Test | ||
def testSetGroupFactory: Unit = { | ||
val schedulerContext = new FIFOSchedulerContextImpl(100) | ||
schedulerContext.setGroupFactory(new FIFOGroupFactory) | ||
val groupFactory = schedulerContext.getOrCreateGroupFactory | ||
assertNotNull(groupFactory) | ||
} | ||
} |
Oops, something went wrong.