...
|
...
|
@@ -7,10 +7,13 @@ import com.yohoufo.common.annotation.IgnoreSignature; |
|
|
import com.yohoufo.common.annotation.InnerApi;
|
|
|
import com.yohoufo.common.cache.RedisLock;
|
|
|
import com.yohoufo.common.exception.UfoServiceException;
|
|
|
import com.yohoufo.common.utils.ExecutorServiceUtils;
|
|
|
import com.yohoufo.common.utils.RandomUtil;
|
|
|
import com.yohoufo.order.model.QuickDeliverOrderContext;
|
|
|
import com.yohoufo.order.model.request.TransferMoneyRequest;
|
|
|
import com.yohoufo.order.service.impl.TransferService;
|
|
|
import com.yohoufo.order.utils.NamedThreadFactory;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.RandomUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
...
|
...
|
@@ -18,8 +21,13 @@ import org.springframework.web.bind.annotation.RequestMapping; |
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.util.UUID;
|
|
|
import java.util.concurrent.ArrayBlockingQueue;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.IntStream;
|
|
|
|
|
|
@Slf4j
|
|
|
@RestController
|
|
|
@RequestMapping("/erp/order/help")
|
|
|
public class OrderHelpController {
|
...
|
...
|
@@ -52,27 +60,36 @@ public class OrderHelpController { |
|
|
@InnerApi
|
|
|
@RequestMapping(value = "/lock")
|
|
|
public ApiResponse lock(String key) {
|
|
|
ExecutorService executorService = new ThreadPoolExecutor(5, 10,
|
|
|
60, TimeUnit.SECONDS,
|
|
|
new ArrayBlockingQueue<>(1000), NamedThreadFactory.newThreadFactory("test"));
|
|
|
|
|
|
IntStream.range(0, 100)
|
|
|
.forEach(i -> executorService.submit(() -> lockTest(key)));
|
|
|
ExecutorServiceUtils.shutdownAndAwaitTermination(executorService);
|
|
|
return new ApiResponse.ApiResponseBuilder()
|
|
|
.code(200)
|
|
|
.message("ok")
|
|
|
.build();
|
|
|
}
|
|
|
|
|
|
private void lockTest(String key) {
|
|
|
RedisKeyBuilder redisLockKey = RedisKeyBuilder.newInstance()
|
|
|
.appendFixed("ufo:order:lock:test:")
|
|
|
.appendVar(key);
|
|
|
String value = UUID.randomUUID().toString();
|
|
|
String message;
|
|
|
if (redisLock.acquire(redisLockKey, value, 5, TimeUnit.SECONDS)) {
|
|
|
try {
|
|
|
log.info("lock test {}, {} i got the lock", key, value);
|
|
|
Thread.sleep(RandomUtils.nextInt(10, 50));
|
|
|
message = "ok";
|
|
|
} catch (InterruptedException e) {
|
|
|
message = "ko doing";
|
|
|
|
|
|
} finally {
|
|
|
redisLock.release(redisLockKey, value);
|
|
|
}
|
|
|
} else {
|
|
|
message = "ko acquire";
|
|
|
log.info("lock test {}, {} i not got the lock", key, value);
|
|
|
}
|
|
|
return new ApiResponse.ApiResponseBuilder()
|
|
|
.code(200)
|
|
|
.message(message)
|
|
|
.build();
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
|