-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
王程明
committed
Jun 17, 2017
1 parent
f1846d6
commit 1d8b7a6
Showing
3 changed files
with
69 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/test/java/com/qiyi/mbd/meerkat/meter/MultiInstanceCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.qiyi.mbd.meerkat.meter; | ||
|
||
import com.google.common.base.Optional; | ||
import com.qiyi.mbd.meerkat.fusing.FusingCommand; | ||
import com.qiyi.mbd.meerkat.fusing.FusingMeter; | ||
|
||
/** | ||
* Created by chengmingwang on 6/10/17. | ||
*/ | ||
public class MultiInstanceCommand extends FusingCommand<Integer> { | ||
|
||
private static final int successRateA = 100; //实例A成功率100% | ||
private static final int successRateB = 60; //实例B成功率60% | ||
private static int counterA = 0; | ||
private static int counterB = 0; | ||
|
||
private final String instance; | ||
|
||
public MultiInstanceCommand(String instance) { | ||
super(instance, APPFusingConfig.class); | ||
this.instance = instance; | ||
} | ||
|
||
@Override | ||
protected Optional<Integer> run() { | ||
if(this.instance.equals("A")){ | ||
counterA += 1; | ||
if (counterA % 100 >= successRateA) { | ||
return null; | ||
} else { | ||
return Optional.fromNullable(1); | ||
} | ||
} else { | ||
counterB += 1; | ||
if (counterB % 100 >= successRateB) { | ||
return null; | ||
} else { | ||
return Optional.fromNullable(1); | ||
} | ||
} | ||
} | ||
|
||
public FusingMeter getMeter() { | ||
return this.meter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters