feat(infra): SyncPutQueuePolicyTest #1336

1. Add the open source agreement to the top, and leave a blank line with package

Co-authored-by: rnmb<19276209+rnmb@users.noreply.github.com>
pull/1344/head
rnmb 2 years ago
parent 3a520d22d9
commit 98e77f8e39

@ -1,10 +1,29 @@
/*
* 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 cn.hippo4j.common.executor.support;
import cn.hippo4j.common.toolkit.ThreadUtil;
import org.junit.Assert;
import org.junit.Test;
import java.util.concurrent.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;
/**
@ -16,7 +35,7 @@ public class SyncPutQueuePolicyTest {
* test thread pool rejected execution
*/
@Test
public void testRejectedExecution() throws InterruptedException {
public void testRejectedExecution() {
SyncPutQueuePolicy syncPutQueuePolicy = new SyncPutQueuePolicy();
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 2,
60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(1), syncPutQueuePolicy);
@ -24,7 +43,7 @@ public class SyncPutQueuePolicyTest {
Assert.assertSame(syncPutQueuePolicy, threadPoolExecutor.getRejectedExecutionHandler());
IntStream.range(0, 4).forEach(s -> {
threadPoolExecutor.execute(() -> ThreadUtil.sleep(500L));
threadPoolExecutor.execute(() -> ThreadUtil.sleep(200L));
});
threadPoolExecutor.shutdown();
while (!threadPoolExecutor.isTerminated()) {

Loading…
Cancel
Save