MCPcopy Create free account
hub / github.com/e2wugui/zeze / testRank

Method testRank

ZezeJava/ZezeJavaTest/src/UnitTest/Zeze/Game/TestRank.java:67–114  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65 }
66
67 public void testRank() {
68 if (disableTest)
69 return;
70
71 try {
72 System.out.println("------ testRank begin");
73 SimpleApp app = apps[0]; // 可以随便取一个, 不过都是对称的, 应该不用都测
74
75 app.rank.setFuncConcurrentLevel(rankType -> CONC_LEVEL);
76 int concLevel = app.rank.getConcurrentLevel(RANK_TYPE);
77 var rankKey = Rank.newRankKey(RANK_TYPE, BConcurrentKey.TimeTypeTotal);
78 LongUnaryOperator roleId2Value = roleId -> roleId * 10;
79
80 for (int hash = 0; hash < concLevel; hash++) {
81 int h = hash;
82 long roleId = ROLE_ID_BEGIN + h;
83 app.getZeze().newProcedure(() -> {
84 app.rank.updateRank(h, rankKey, roleId, new BValueLong(roleId2Value.applyAsLong(roleId))).await().onSuccess(r -> {
85 assertNotNull(r);
86 assertEquals(Procedure.Success, r.longValue());
87 }).onFail(e -> {
88 e.printStackTrace();
89 fail();
90 });
91 return Procedure.Success;
92 }, "updateRank").call();
93 }
94
95 app.getZeze().newProcedure(() -> {
96 // 直接从数据库读取并合并
97 var result = app.rank.getRankDirect(rankKey);
98// System.out.format("--- getRankDirect: concurrent=%d, rankList=[%d]:%s%n",
99// concLevel, result.getRankList().size(), result);
100 assertEquals(concLevel, result.getRankList().size());
101 for (BRankValue rank : result.getRankList()) {
102 assertTrue(rank.getRoleId() >= ROLE_ID_BEGIN && rank.getRoleId() < ROLE_ID_BEGIN + concLevel);
103 assertEquals(roleId2Value.applyAsLong(rank.getRoleId()), ((BValueLong)rank.getDynamic().getBean()).getValue());
104 }
105 return Procedure.Success;
106 }, "getRankDirect").call();
107 } catch (Throwable e) {
108 // print stacktrace.
109 e.printStackTrace();
110 throw e;
111 } finally {
112 System.out.println("------ testRank end");
113 }
114 }
115
116 // 用于生成Redirect代码
117 public static void main(String[] args) throws Exception {

Callers 1

mainMethod · 0.95

Calls 15

newRankKeyMethod · 0.95
getZezeMethod · 0.95
onFailMethod · 0.80
onSuccessMethod · 0.80
getRankDirectMethod · 0.80
getRankListMethod · 0.80
getDynamicMethod · 0.80
callMethod · 0.65
awaitMethod · 0.65
sizeMethod · 0.65
getRoleIdMethod · 0.65

Tested by

no test coverage detected