in src/productservice/productservice-provider/src/main/java/com/alibabacloud/hipstershop/productservice/service/ProductServiceImpl.java [44:75]
public List<ProductItem> confirmInventory(List<ProductItem> checkoutProductItems) {
if(!"".equals(exceptionIps) && !"".equals(exceptionType)){
String ip = getLocalIp();
Set<String> ips = new HashSet<>(Arrays.asList(exceptionIps.split(",")));
if(ips.contains(ip)) {
Random random = new Random();
int i = random.nextInt(100);
if (i < rate) {
if(Constant.SLEEP.equals(exceptionType)) {
try {
Thread.sleep(exceptionValue);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
else if(Constant.FULL_GC.equals(exceptionType)) {
List<Object> list = new ArrayList<>();
for(int j = 0; j < exceptionValue; j++) {
list.add(new byte[10 * 1024 * 1024]);
System.gc();
}
list = null;
}
}
}
}
for (ProductItem item : checkoutProductItems) {
//@TODO check inventory
item.setLock(true);
}
return checkoutProductItems;
}