mirror of https://github.com/longtai-cn/hippo4j
# Conflicts: # docs/docs/user_docs/other/issue.mdpull/635/head
commit
738a0a0bbd
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"label": "贡献规约",
|
||||||
|
"position": 2,
|
||||||
|
"link": {
|
||||||
|
"type": "generated-index"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
sidebar_position: 2
|
||||||
|
---
|
||||||
|
|
||||||
|
# 代码规约
|
||||||
|
|
||||||
|
1. 代码提交前,执行 `mvn spotless:apply` 保证代码格式符合规范。
|
||||||
|
2. 代码中不要出现无意义的空行。
|
@ -0,0 +1,59 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>cn.hippo4j</groupId>
|
||||||
|
<artifactId>hippo4j-adapter</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>hippo4j-adapter-alibaba-dubbo</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<alibaba-dubbo.version>2.6.12</alibaba-dubbo.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hippo4j</groupId>
|
||||||
|
<artifactId>hippo4j-adapter-base</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>dubbo</artifactId>
|
||||||
|
<version>${alibaba-dubbo.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifestEntries>
|
||||||
|
<Implementation-Title>${project.artifactId}</Implementation-Title>
|
||||||
|
<Implementation-Version>${project.version}</Implementation-Version>
|
||||||
|
<Build-Time>${maven.build.timestamp}</Build-Time>
|
||||||
|
<Built-By>chen.ma</Built-By>
|
||||||
|
</manifestEntries>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<version>2.10.3</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>jar</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* 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.adapter.alibaba.dubbo;
|
||||||
|
|
||||||
|
import cn.hippo4j.adapter.base.ThreadPoolAdapter;
|
||||||
|
import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter;
|
||||||
|
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
|
||||||
|
import com.alibaba.dubbo.common.extension.ExtensionLoader;
|
||||||
|
import com.alibaba.dubbo.common.store.DataStore;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
||||||
|
import org.springframework.context.ApplicationListener;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
|
import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMITER;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alibaba Dubbo thread-pool adapter.
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class AlibabaDubboThreadPoolAdapter implements ThreadPoolAdapter, ApplicationListener<ApplicationStartedEvent> {
|
||||||
|
|
||||||
|
private final Map<String, ThreadPoolExecutor> DUBBO_PROTOCOL_EXECUTOR = Maps.newHashMap();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String mark() {
|
||||||
|
return "AlibabaDubbo";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ThreadPoolAdapterState getThreadPoolState(String identify) {
|
||||||
|
ThreadPoolAdapterState threadPoolAdapterState = new ThreadPoolAdapterState();
|
||||||
|
ThreadPoolExecutor executor = DUBBO_PROTOCOL_EXECUTOR.get(identify);
|
||||||
|
if (executor == null) {
|
||||||
|
log.warn("[{}] Alibaba Dubbo consuming thread pool not found.", identify);
|
||||||
|
return threadPoolAdapterState;
|
||||||
|
}
|
||||||
|
threadPoolAdapterState.setThreadPoolKey(identify);
|
||||||
|
threadPoolAdapterState.setCoreSize(executor.getCorePoolSize());
|
||||||
|
threadPoolAdapterState.setMaximumSize(executor.getMaximumPoolSize());
|
||||||
|
return threadPoolAdapterState;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ThreadPoolAdapterState> getThreadPoolStates() {
|
||||||
|
List<ThreadPoolAdapterState> threadPoolAdapterStates = new ArrayList<>();
|
||||||
|
DUBBO_PROTOCOL_EXECUTOR.forEach((kel, val) -> threadPoolAdapterStates.add(getThreadPoolState(String.valueOf(val))));
|
||||||
|
return threadPoolAdapterStates;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateThreadPool(ThreadPoolAdapterParameter threadPoolAdapterParameter) {
|
||||||
|
String threadPoolKey = threadPoolAdapterParameter.getThreadPoolKey();
|
||||||
|
ThreadPoolExecutor executor = DUBBO_PROTOCOL_EXECUTOR.get(threadPoolAdapterParameter.getThreadPoolKey());
|
||||||
|
if (executor == null) {
|
||||||
|
log.warn("[{}] Alibaba Dubbo consuming thread pool not found.", threadPoolKey);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int originalCoreSize = executor.getCorePoolSize();
|
||||||
|
int originalMaximumPoolSize = executor.getMaximumPoolSize();
|
||||||
|
executor.setCorePoolSize(threadPoolAdapterParameter.getCorePoolSize());
|
||||||
|
executor.setMaximumPoolSize(threadPoolAdapterParameter.getMaximumPoolSize());
|
||||||
|
log.info("[{}] Alibaba Dubbo consumption thread pool parameter change. coreSize: {}, maximumSize: {}",
|
||||||
|
threadPoolKey,
|
||||||
|
String.format(CHANGE_DELIMITER, originalCoreSize, executor.getCorePoolSize()),
|
||||||
|
String.format(CHANGE_DELIMITER, originalMaximumPoolSize, executor.getMaximumPoolSize()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onApplicationEvent(ApplicationStartedEvent event) {
|
||||||
|
String poolKey = ExecutorService.class.getName();
|
||||||
|
try {
|
||||||
|
DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
|
||||||
|
Map<String, Object> executors = dataStore.get(poolKey);
|
||||||
|
executors.forEach((key, value) -> DUBBO_PROTOCOL_EXECUTOR.put(key, (ThreadPoolExecutor) value));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
log.error("Failed to get Alibaba Dubbo protocol thread pool", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>cn.hippo4j</groupId>
|
||||||
|
<artifactId>hippo4j-adapter</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>hippo4j-adapter-spring-cloud-stream-rabbitmq</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hippo4j</groupId>
|
||||||
|
<artifactId>hippo4j-adapter-base</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
|
||||||
|
<version>${spring-cloud-starter-stream-rabbitmq.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifestEntries>
|
||||||
|
<Implementation-Title>${project.artifactId}</Implementation-Title>
|
||||||
|
<Implementation-Version>${project.version}</Implementation-Version>
|
||||||
|
<Build-Time>${maven.build.timestamp}</Build-Time>
|
||||||
|
<Built-By>chen.ma</Built-By>
|
||||||
|
</manifestEntries>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<version>2.10.3</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>jar</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,163 @@
|
|||||||
|
/*
|
||||||
|
* 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.adapter.springcloud.stream.rabbitmq;
|
||||||
|
|
||||||
|
import cn.hippo4j.adapter.base.ThreadPoolAdapter;
|
||||||
|
import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter;
|
||||||
|
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
|
||||||
|
import cn.hippo4j.common.config.ApplicationContextHolder;
|
||||||
|
import cn.hippo4j.common.toolkit.CollectionUtil;
|
||||||
|
import cn.hippo4j.common.toolkit.ReflectUtil;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer;
|
||||||
|
import org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer;
|
||||||
|
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
|
||||||
|
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
||||||
|
import org.springframework.cloud.stream.binder.Binding;
|
||||||
|
import org.springframework.cloud.stream.binder.DefaultBinding;
|
||||||
|
import org.springframework.cloud.stream.binding.InputBindingLifecycle;
|
||||||
|
import org.springframework.context.ApplicationListener;
|
||||||
|
import org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMITER;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spring cloud stream rabbimq thread-pool adapter.
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class SpringCloudStreamRabbitMQThreadPoolAdapter implements ThreadPoolAdapter, ApplicationListener<ApplicationStartedEvent> {
|
||||||
|
|
||||||
|
private final Map<String, AbstractMessageListenerContainer> ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR = Maps.newHashMap();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String mark() {
|
||||||
|
return "RabbitMQSpringCloudStream";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ThreadPoolAdapterState getThreadPoolState(String identify) {
|
||||||
|
ThreadPoolAdapterState result = new ThreadPoolAdapterState();
|
||||||
|
AbstractMessageListenerContainer messageListenerContainer = ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR.get(identify);
|
||||||
|
if (messageListenerContainer != null) {
|
||||||
|
result.setThreadPoolKey(identify);
|
||||||
|
if (messageListenerContainer instanceof SimpleMessageListenerContainer) {
|
||||||
|
int concurrentConsumers = (int) ReflectUtil.getFieldValue(messageListenerContainer, "concurrentConsumers");
|
||||||
|
result.setCoreSize(concurrentConsumers);
|
||||||
|
Object maxConcurrentConsumers = ReflectUtil.getFieldValue(messageListenerContainer, "maxConcurrentConsumers");
|
||||||
|
if (maxConcurrentConsumers != null) {
|
||||||
|
result.setMaximumSize((Integer) maxConcurrentConsumers);
|
||||||
|
} else {
|
||||||
|
result.setMaximumSize(concurrentConsumers);
|
||||||
|
}
|
||||||
|
} else if (messageListenerContainer instanceof DirectMessageListenerContainer) {
|
||||||
|
int consumersPerQueue = (int) ReflectUtil.getFieldValue(messageListenerContainer, "consumersPerQueue");
|
||||||
|
result.setCoreSize(consumersPerQueue);
|
||||||
|
result.setMaximumSize(consumersPerQueue);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
log.warn("[{}] RabbitMQ consuming thread pool not found.", identify);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ThreadPoolAdapterState> getThreadPoolStates() {
|
||||||
|
List<ThreadPoolAdapterState> adapterStateList = Lists.newArrayList();
|
||||||
|
ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR.forEach(
|
||||||
|
(key, val) -> adapterStateList.add(getThreadPoolState(key)));
|
||||||
|
return adapterStateList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateThreadPool(ThreadPoolAdapterParameter threadPoolAdapterParameter) {
|
||||||
|
String threadPoolKey = threadPoolAdapterParameter.getThreadPoolKey();
|
||||||
|
AbstractMessageListenerContainer messageListenerContainer = ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR.get(threadPoolKey);
|
||||||
|
if (messageListenerContainer != null) {
|
||||||
|
synchronized (ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR) {
|
||||||
|
Integer corePoolSize = threadPoolAdapterParameter.getCorePoolSize();
|
||||||
|
Integer maximumPoolSize = threadPoolAdapterParameter.getMaximumPoolSize();
|
||||||
|
if (messageListenerContainer instanceof SimpleMessageListenerContainer) {
|
||||||
|
int originalCoreSize = (int) ReflectUtil.getFieldValue(messageListenerContainer, "concurrentConsumers");
|
||||||
|
Object maxConcurrentConsumers = ReflectUtil.getFieldValue(messageListenerContainer, "maxConcurrentConsumers");
|
||||||
|
int originalMaximumPoolSize;
|
||||||
|
if (maxConcurrentConsumers != null) {
|
||||||
|
originalMaximumPoolSize = (Integer) maxConcurrentConsumers;
|
||||||
|
} else {
|
||||||
|
originalMaximumPoolSize = originalCoreSize;
|
||||||
|
}
|
||||||
|
SimpleMessageListenerContainer simpleMessageListenerContainer = (SimpleMessageListenerContainer) messageListenerContainer;
|
||||||
|
if (originalCoreSize > maximumPoolSize) {
|
||||||
|
simpleMessageListenerContainer.setConcurrentConsumers(corePoolSize);
|
||||||
|
simpleMessageListenerContainer.setMaxConcurrentConsumers(maximumPoolSize);
|
||||||
|
} else {
|
||||||
|
simpleMessageListenerContainer.setMaxConcurrentConsumers(maximumPoolSize);
|
||||||
|
simpleMessageListenerContainer.setConcurrentConsumers(corePoolSize);
|
||||||
|
}
|
||||||
|
log.info("[{}] RabbitMQ consumption thread pool parameter change. coreSize: {}, maximumSize: {}",
|
||||||
|
threadPoolKey,
|
||||||
|
String.format(CHANGE_DELIMITER, originalCoreSize, corePoolSize),
|
||||||
|
String.format(CHANGE_DELIMITER, originalMaximumPoolSize, maximumPoolSize));
|
||||||
|
} else if (messageListenerContainer instanceof DirectMessageListenerContainer) {
|
||||||
|
int originalCoreSize = (int) ReflectUtil.getFieldValue(messageListenerContainer, "consumersPerQueue");
|
||||||
|
DirectMessageListenerContainer directMessageListenerContainer = (DirectMessageListenerContainer) messageListenerContainer;
|
||||||
|
directMessageListenerContainer.setConsumersPerQueue(maximumPoolSize);
|
||||||
|
log.info("[{}] RabbitMQ consumption thread pool parameter change. coreSize: {}",
|
||||||
|
threadPoolKey,
|
||||||
|
String.format(CHANGE_DELIMITER, originalCoreSize, corePoolSize));
|
||||||
|
} else {
|
||||||
|
log.warn("[{}] RabbitMQ consuming thread pool not support. messageListenerContainer: {}", threadPoolKey, messageListenerContainer.getClass());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
log.warn("[{}] RabbitMQ consuming thread pool not found.", threadPoolKey);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onApplicationEvent(ApplicationStartedEvent event) {
|
||||||
|
InputBindingLifecycle bindingLifecycle = ApplicationContextHolder.getBean(InputBindingLifecycle.class);
|
||||||
|
Collection<Binding<Object>> inputBindings = Optional.ofNullable(ReflectUtil.getFieldValue(bindingLifecycle, "inputBindings"))
|
||||||
|
.map(each -> (Collection<Binding<Object>>) each).orElse(null);
|
||||||
|
if (CollectionUtil.isEmpty(inputBindings)) {
|
||||||
|
log.info("InputBindings record not found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
for (Binding<Object> each : inputBindings) {
|
||||||
|
String bindingName = each.getBindingName();
|
||||||
|
DefaultBinding defaultBinding = (DefaultBinding) each;
|
||||||
|
Object lifecycle = ReflectUtil.getFieldValue(defaultBinding, "lifecycle");
|
||||||
|
if (lifecycle instanceof AmqpInboundChannelAdapter) {
|
||||||
|
AbstractMessageListenerContainer rabbitMQListenerContainer = (AbstractMessageListenerContainer) ReflectUtil.getFieldValue(lifecycle, "messageListenerContainer");
|
||||||
|
ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR.put(bindingName, rabbitMQListenerContainer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
log.error("Failed to get input-bindings thread pool.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* 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 java.util.concurrent.BlockingQueue;
|
||||||
|
import java.util.concurrent.RejectedExecutionHandler;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the oldest task policy.
|
||||||
|
*/
|
||||||
|
public class RunsOldestTaskPolicy implements RejectedExecutionHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
|
||||||
|
if (executor.isShutdown()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BlockingQueue<Runnable> workQueue = executor.getQueue();
|
||||||
|
Runnable firstWork = workQueue.poll();
|
||||||
|
boolean newTaskAdd = workQueue.offer(r);
|
||||||
|
if (firstWork != null) {
|
||||||
|
firstWork.run();
|
||||||
|
}
|
||||||
|
if (!newTaskAdd) {
|
||||||
|
executor.execute(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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 lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.util.concurrent.RejectedExecutionHandler;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronous put queue policy.
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class SyncPutQueuePolicy implements RejectedExecutionHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
|
||||||
|
if (executor.isShutdown()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
executor.getQueue().put(r);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log.error("Adding Queue task to thread pool failed.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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 cn.hippo4j.common.model.register.notify;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dynamic thread-pool register core notify parameter.
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DynamicThreadPoolRegisterCoreNotifyParameter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interval
|
||||||
|
*/
|
||||||
|
private Integer interval;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Receive
|
||||||
|
*/
|
||||||
|
private String receives;
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* 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.model.register.notify;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dynamic thread-pool register server notify parameter.
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DynamicThreadPoolRegisterServerNotifyParameter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Platform
|
||||||
|
*/
|
||||||
|
private String platform;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Access token
|
||||||
|
*/
|
||||||
|
private String accessToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interval
|
||||||
|
*/
|
||||||
|
private Integer interval;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Receives
|
||||||
|
*/
|
||||||
|
private String receives;
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* 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.toolkit;
|
||||||
|
|
||||||
|
import cn.hippo4j.common.function.Matcher;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
import org.checkerframework.checker.units.qual.A;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
|
||||||
|
public class ArrayUtilTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertIsEmpty() {
|
||||||
|
String[] array = new String[0];
|
||||||
|
Assert.isTrue(ArrayUtil.isEmpty(array));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertIsNotEmpty() {
|
||||||
|
String[] array = new String[0];
|
||||||
|
Assert.isTrue(!ArrayUtil.isNotEmpty(array));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertFirstMatch() {
|
||||||
|
Matcher<String> matcher = (str) -> "1".equalsIgnoreCase(str);
|
||||||
|
|
||||||
|
String[] array = new String[0];
|
||||||
|
Assert.isTrue(Strings.isNullOrEmpty(ArrayUtil.firstMatch(matcher, array)));
|
||||||
|
|
||||||
|
array = new String[]{"0"};
|
||||||
|
Assert.isTrue(Strings.isNullOrEmpty(ArrayUtil.firstMatch(matcher, array)));
|
||||||
|
|
||||||
|
array = new String[]{"1"};
|
||||||
|
Assert.isTrue(!Strings.isNullOrEmpty(ArrayUtil.firstMatch(matcher, array)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertAddAll() {
|
||||||
|
String[] array = new String[]{"1"};
|
||||||
|
Assert.isTrue(ArrayUtil.addAll(array, null).length == 1);
|
||||||
|
Assert.isTrue(ArrayUtil.addAll(null, array).length == 1);
|
||||||
|
|
||||||
|
Assert.isTrue(ArrayUtil.addAll(array, new String[]{"1"}).length == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertClone() {
|
||||||
|
Assert.isNull(ArrayUtil.clone(null));
|
||||||
|
|
||||||
|
String[] array = new String[0];
|
||||||
|
Assert.isTrue(array != ArrayUtil.clone(array));
|
||||||
|
Assert.isTrue(array.length == ArrayUtil.clone(array).length);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* 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.toolkit;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class BooleanUtilTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertToBoolean() {
|
||||||
|
Assert.isTrue(BooleanUtil.toBoolean("true"));
|
||||||
|
Assert.isTrue(BooleanUtil.toBoolean("yes"));
|
||||||
|
Assert.isTrue(BooleanUtil.toBoolean("1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertIsTrue() {
|
||||||
|
Assert.isTrue(BooleanUtil.isTrue(true));
|
||||||
|
}
|
||||||
|
}
|
@ -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 cn.hippo4j.common.toolkit;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class ByteConvertUtilTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertGetPrintSize() {
|
||||||
|
Assert.isTrue(Objects.equals(ByteConvertUtil.getPrintSize(220), "220B"));
|
||||||
|
Assert.isTrue(Objects.equals(ByteConvertUtil.getPrintSize(2200), "2.15KB"));
|
||||||
|
Assert.isTrue(Objects.equals(ByteConvertUtil.getPrintSize(2200000), "2.10MB"));
|
||||||
|
Assert.isTrue(Objects.equals(ByteConvertUtil.getPrintSize(2200000000L), "2.05GB"));
|
||||||
|
}
|
||||||
|
}
|
@ -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 cn.hippo4j.common.toolkit;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class CalculateUtilTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertDivide() {
|
||||||
|
Assert.isTrue(CalculateUtil.divide(200, 100) == 200);
|
||||||
|
Assert.isTrue(CalculateUtil.divide(100, 200) == 50);
|
||||||
|
Assert.isTrue(CalculateUtil.divide(100, 100) == 100);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* 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.toolkit;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import org.assertj.core.util.Lists;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class CollectionUtilTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertGetFirst() {
|
||||||
|
Assert.isNull(CollectionUtil.getFirst(null));
|
||||||
|
|
||||||
|
String first = CollectionUtil.getFirst(Lists.newArrayList("1", "2"));
|
||||||
|
Assert.notEmpty(first);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertIsEmpty() {
|
||||||
|
List list = null;
|
||||||
|
Assert.isTrue(CollectionUtil.isEmpty(list));
|
||||||
|
|
||||||
|
list = Lists.newArrayList();
|
||||||
|
Assert.isTrue(CollectionUtil.isEmpty(list));
|
||||||
|
|
||||||
|
list = Lists.newArrayList("1");
|
||||||
|
Assert.isTrue(!CollectionUtil.isEmpty(list));
|
||||||
|
|
||||||
|
Map map = null;
|
||||||
|
Assert.isTrue(CollectionUtil.isEmpty(map));
|
||||||
|
|
||||||
|
map = Maps.newHashMap();
|
||||||
|
Assert.isTrue(CollectionUtil.isEmpty(map));
|
||||||
|
|
||||||
|
map.put("key", "value");
|
||||||
|
Assert.isTrue(!CollectionUtil.isEmpty(map));
|
||||||
|
|
||||||
|
Iterator iterator = null;
|
||||||
|
Assert.isTrue(CollectionUtil.isEmpty(iterator));
|
||||||
|
|
||||||
|
iterator = Lists.emptyList().iterator();
|
||||||
|
Assert.isTrue(CollectionUtil.isEmpty(iterator));
|
||||||
|
|
||||||
|
iterator = Lists.newArrayList("1").iterator();
|
||||||
|
Assert.isTrue(!CollectionUtil.isEmpty(iterator));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertIsNotEmpty() {
|
||||||
|
List list = null;
|
||||||
|
Assert.isTrue(!CollectionUtil.isNotEmpty(list));
|
||||||
|
|
||||||
|
list = Lists.newArrayList();
|
||||||
|
Assert.isTrue(!CollectionUtil.isNotEmpty(list));
|
||||||
|
|
||||||
|
list = Lists.newArrayList("1");
|
||||||
|
Assert.isTrue(CollectionUtil.isNotEmpty(list));
|
||||||
|
|
||||||
|
Map map = null;
|
||||||
|
Assert.isTrue(!CollectionUtil.isNotEmpty(map));
|
||||||
|
|
||||||
|
map = Maps.newHashMap();
|
||||||
|
Assert.isTrue(!CollectionUtil.isNotEmpty(map));
|
||||||
|
|
||||||
|
map.put("key", "value");
|
||||||
|
Assert.isTrue(CollectionUtil.isNotEmpty(map));
|
||||||
|
|
||||||
|
Iterator iterator = null;
|
||||||
|
Assert.isTrue(!CollectionUtil.isNotEmpty(iterator));
|
||||||
|
|
||||||
|
iterator = Lists.emptyList().iterator();
|
||||||
|
Assert.isTrue(!CollectionUtil.isNotEmpty(iterator));
|
||||||
|
|
||||||
|
iterator = Lists.newArrayList("1").iterator();
|
||||||
|
Assert.isTrue(CollectionUtil.isNotEmpty(iterator));
|
||||||
|
}
|
||||||
|
}
|
@ -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 cn.hippo4j.common.toolkit;
|
||||||
|
|
||||||
|
import cn.hippo4j.common.function.NoArgsConsumer;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
public class ConditionUtilTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertCondition() {
|
||||||
|
// init consumer
|
||||||
|
AtomicBoolean checkValue = new AtomicBoolean(false);
|
||||||
|
NoArgsConsumer trueConsumer = () -> checkValue.set(true);
|
||||||
|
NoArgsConsumer falseConsumer = () -> checkValue.set(false);
|
||||||
|
// test trueConsumer run
|
||||||
|
ConditionUtil.condition(true, trueConsumer, falseConsumer);
|
||||||
|
Assert.isTrue(checkValue.get());
|
||||||
|
// test falseConsumer run
|
||||||
|
ConditionUtil.condition(false, trueConsumer, falseConsumer);
|
||||||
|
Assert.isTrue(!checkValue.get());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* 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.toolkit;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class ContentUtilTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertGetPoolContent() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertGetGroupKey() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertGetGroupKeys() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -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 cn.hippo4j.common.toolkit;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class FileUtilTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertReadUtf8String() {
|
||||||
|
String testText = "abcd简体繁体\uD83D\uDE04\uD83D\uDD25& *\n" +
|
||||||
|
"second line\n" +
|
||||||
|
"empty line next\n";
|
||||||
|
String testFilePath = "test/test_utf8.txt";
|
||||||
|
String contentByFileUtil = FileUtil.readUtf8String(testFilePath);
|
||||||
|
Assert.isTrue(testText.equals(contentByFileUtil));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* 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.toolkit;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JSON util test.
|
||||||
|
*/
|
||||||
|
public class JSONUtilTest {
|
||||||
|
|
||||||
|
private static final Foo EXPECTED_FOO = new Foo(1, "foo1", new Foo(2, "foo2", null));
|
||||||
|
private static final List<Foo> EXPECTED_FOO_ARRAY = Arrays.asList(EXPECTED_FOO, EXPECTED_FOO);
|
||||||
|
private static final String EXPECTED_FOO_JSON = "{\"id\":1,\"name\":\"foo1\",\"foo\":{\"id\":2,\"name\":\"foo2\"}}";
|
||||||
|
private static final String EXPECTED_FOO_JSON_ARRAY = "[" + EXPECTED_FOO_JSON + "," + EXPECTED_FOO_JSON + "]";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertToJSONString() {
|
||||||
|
Assert.assertNull(JSONUtil.toJSONString(null));
|
||||||
|
Assert.assertEquals(EXPECTED_FOO_JSON, JSONUtil.toJSONString(EXPECTED_FOO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertParseObject() {
|
||||||
|
Assert.assertNull(JSONUtil.parseObject(null, Foo.class));
|
||||||
|
Assert.assertNull(JSONUtil.parseObject(" ", Foo.class));
|
||||||
|
Assert.assertEquals(EXPECTED_FOO, JSONUtil.parseObject(EXPECTED_FOO_JSON, Foo.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertParseObjectTypeReference() {
|
||||||
|
Assert.assertNull(JSONUtil.parseObject(null, new TypeReference<List<Foo>>() {}));
|
||||||
|
Assert.assertNull(JSONUtil.parseObject(" ", new TypeReference<List<Foo>>() {}));
|
||||||
|
Assert.assertEquals(
|
||||||
|
EXPECTED_FOO_ARRAY,
|
||||||
|
JSONUtil.parseObject(EXPECTED_FOO_JSON_ARRAY, new TypeReference<List<Foo>>() {})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertParseArray() {
|
||||||
|
Assert.assertNull(JSONUtil.parseArray(null, Foo.class));
|
||||||
|
Assert.assertNull(JSONUtil.parseArray(" ", Foo.class));
|
||||||
|
Assert.assertEquals(
|
||||||
|
EXPECTED_FOO_ARRAY,
|
||||||
|
JSONUtil.parseArray(EXPECTED_FOO_JSON_ARRAY, Foo.class)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EqualsAndHashCode
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
private static class Foo {
|
||||||
|
private Integer id;
|
||||||
|
private String name;
|
||||||
|
private Foo foo;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
abcd简体繁体😄🔥& *
|
||||||
|
second line
|
||||||
|
empty line next
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
|||||||
.waves-ripple{position:absolute;border-radius:100%;background-color:rgba(0,0,0,.15);background-clip:padding-box;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-transform:scale(0);transform:scale(0);opacity:1}.waves-ripple.z-active{opacity:0;-webkit-transform:scale(2);transform:scale(2);-webkit-transition:opacity 1.2s ease-out,-webkit-transform .6s ease-out;transition:opacity 1.2s ease-out,-webkit-transform .6s ease-out;transition:opacity 1.2s ease-out,transform .6s ease-out;transition:opacity 1.2s ease-out,transform .6s ease-out,-webkit-transform .6s ease-out}.dashboard-editor-container[data-v-001a3100]{padding:32px;background-color:#f0f2f5;position:relative;min-height:100vh}
|
.waves-ripple{position:absolute;border-radius:100%;background-color:rgba(0,0,0,.15);background-clip:padding-box;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-transform:scale(0);transform:scale(0);opacity:1}.waves-ripple.z-active{opacity:0;-webkit-transform:scale(2);transform:scale(2);-webkit-transition:opacity 1.2s ease-out,-webkit-transform .6s ease-out;transition:opacity 1.2s ease-out,-webkit-transform .6s ease-out;transition:opacity 1.2s ease-out,transform .6s ease-out;transition:opacity 1.2s ease-out,transform .6s ease-out,-webkit-transform .6s ease-out}.dashboard-editor-container[data-v-58ed3ad9]{padding:32px;background-color:#f0f2f5;position:relative;min-height:100vh}
|
@ -0,0 +1 @@
|
|||||||
|
.waves-ripple{position:absolute;border-radius:100%;background-color:rgba(0,0,0,.15);background-clip:padding-box;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-transform:scale(0);transform:scale(0);opacity:1}.waves-ripple.z-active{opacity:0;-webkit-transform:scale(2);transform:scale(2);-webkit-transition:opacity 1.2s ease-out,-webkit-transform .6s ease-out;transition:opacity 1.2s ease-out,-webkit-transform .6s ease-out;transition:opacity 1.2s ease-out,transform .6s ease-out;transition:opacity 1.2s ease-out,transform .6s ease-out,-webkit-transform .6s ease-out}
|
@ -0,0 +1 @@
|
|||||||
|
.waves-ripple{position:absolute;border-radius:100%;background-color:rgba(0,0,0,.15);background-clip:padding-box;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-transform:scale(0);transform:scale(0);opacity:1}.waves-ripple.z-active{opacity:0;-webkit-transform:scale(2);transform:scale(2);-webkit-transition:opacity 1.2s ease-out,-webkit-transform .6s ease-out;transition:opacity 1.2s ease-out,-webkit-transform .6s ease-out;transition:opacity 1.2s ease-out,transform .6s ease-out;transition:opacity 1.2s ease-out,transform .6s ease-out,-webkit-transform .6s ease-out}
|
@ -1 +1 @@
|
|||||||
.waves-ripple{position:absolute;border-radius:100%;background-color:rgba(0,0,0,.15);background-clip:padding-box;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-transform:scale(0);transform:scale(0);opacity:1}.waves-ripple.z-active{opacity:0;-webkit-transform:scale(2);transform:scale(2);-webkit-transition:opacity 1.2s ease-out,-webkit-transform .6s ease-out;transition:opacity 1.2s ease-out,-webkit-transform .6s ease-out;transition:opacity 1.2s ease-out,transform .6s ease-out;transition:opacity 1.2s ease-out,transform .6s ease-out,-webkit-transform .6s ease-out}.pagination-container[data-v-df7d1fa0]{background:#fff;padding:32px 16px}.pagination-container.hidden[data-v-df7d1fa0]{display:none}[data-v-40b8bf28]::-webkit-scrollbar{width:8px;height:8px}[data-v-40b8bf28]::-webkit-scrollbar-track{border-radius:5px;background:rgba(0,0,0,.06);-webkit-box-shadow:inset 0 0 5px rgba(0,0,0,.08)}[data-v-40b8bf28]::-webkit-scrollbar-thumb{border-radius:5px;background:rgba(0,0,0,.12);-webkit-box-shadow:inset 0 0 10px rgba(0,0,0,.2)}.stack-info[data-v-40b8bf28]{height:400px;overflow:auto}.stack-info>li[data-v-40b8bf28]{margin-bottom:24px}.stack-info>li p[data-v-40b8bf28]:first-child{color:#06f;font-weight:600;margin-top:10px}.stack-info>li ul[data-v-40b8bf28]{margin-left:30px}.stack-info>li ul li[data-v-40b8bf28]{color:#fc5531;text-align:justify;margin:10px auto}
|
.waves-ripple{position:absolute;border-radius:100%;background-color:rgba(0,0,0,.15);background-clip:padding-box;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-transform:scale(0);transform:scale(0);opacity:1}.waves-ripple.z-active{opacity:0;-webkit-transform:scale(2);transform:scale(2);-webkit-transition:opacity 1.2s ease-out,-webkit-transform .6s ease-out;transition:opacity 1.2s ease-out,-webkit-transform .6s ease-out;transition:opacity 1.2s ease-out,transform .6s ease-out;transition:opacity 1.2s ease-out,transform .6s ease-out,-webkit-transform .6s ease-out}.pagination-container[data-v-df7d1fa0]{background:#fff;padding:32px 16px}.pagination-container.hidden[data-v-df7d1fa0]{display:none}[data-v-65a213ee]::-webkit-scrollbar{width:8px;height:8px}[data-v-65a213ee]::-webkit-scrollbar-track{border-radius:5px;background:rgba(0,0,0,.06);-webkit-box-shadow:inset 0 0 5px rgba(0,0,0,.08)}[data-v-65a213ee]::-webkit-scrollbar-thumb{border-radius:5px;background:rgba(0,0,0,.12);-webkit-box-shadow:inset 0 0 10px rgba(0,0,0,.2)}.stack-info[data-v-65a213ee]{height:400px;overflow:auto}.stack-info>li[data-v-65a213ee]{margin-bottom:24px}.stack-info>li p[data-v-65a213ee]:first-child{color:#06f;font-weight:600;margin-top:10px}.stack-info>li ul[data-v-65a213ee]{margin-left:30px}.stack-info>li ul li[data-v-65a213ee]{color:#fc5531;text-align:justify;margin:10px auto}
|
@ -0,0 +1 @@
|
|||||||
|
.waves-ripple{position:absolute;border-radius:100%;background-color:rgba(0,0,0,.15);background-clip:padding-box;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-transform:scale(0);transform:scale(0);opacity:1}.waves-ripple.z-active{opacity:0;-webkit-transform:scale(2);transform:scale(2);-webkit-transition:opacity 1.2s ease-out,-webkit-transform .6s ease-out;transition:opacity 1.2s ease-out,-webkit-transform .6s ease-out;transition:opacity 1.2s ease-out,transform .6s ease-out;transition:opacity 1.2s ease-out,transform .6s ease-out,-webkit-transform .6s ease-out}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue