Skip to content

Commit

Permalink
[WIP]add test case for [linkis-scheduler] #1914 (#2205)
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
QuintinTao and “e authored Jun 5, 2022
1 parent d57abbc commit 32aac24
Show file tree
Hide file tree
Showing 17 changed files with 630 additions and 0 deletions.
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)
}
}
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)
}
}
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)
}

}
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)
}

}
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)
}

}
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)
}

}

}
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)
}
}
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)
}
}
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)
}
}
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)
}
}
Loading

0 comments on commit 32aac24

Please sign in to comment.