MkCounter.java returns timestamps instead of counter values
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
開啟 src/main/java/co/stateful/mock/MkCounter.java,查看第 29–36 行,其中 set 為空,incrementAndGet 會回傳 System.currentTimeMillis()。依照 issue 中的程式碼片段所示,新增一個 AtomicLong 欄位,並將這兩個方法都委派給它。完成的標準是:counter.set(10L) 後接 counter.incrementAndGet(-3L) 會回傳 7,且正、零和負增量在同一實例上的行為都正確;執行 src/test/java 下與 mock 相關的測試來確認。
由索引模型根據 Issue 內容生成。
描述
MkCounter never stores a counter value: set() discards its argument, and incrementAndGet() ignores the delta and returns the wall-clock time. Code using the mock therefore gets a timestamp instead of the counter result, even though the mock package documents using MkSttc as a normal adapter in unit tests.
In src/main/java/co/stateful/mock/MkCounter.java, lines 29–36:
public void set(final long value) {
// done
}
public long incrementAndGet(final long delta) {
return System.currentTimeMillis();
}
For example, on a single counter instance:
Counter counter = new MkSttc().counters().get("hits");
counter.set(10L);
long result = counter.incrementAndGet(-3L);
// Expected: 7L. Actual: current epoch time in milliseconds.
Keep the value in an AtomicLong field and delegate both operations to it:
private final AtomicLong value = new AtomicLong();
public void set(final long number) {
this.value.set(number);
}
public long incrementAndGet(final long delta) {
return this.value.addAndGet(delta);
}
This confines the fix to MkCounter and makes positive, zero, and negative deltas follow the Counter contract on the same instance.
- 主要語言
- Java
- 星號
- 10
- 分支
- 3
- 平均合併
- 6 小時 5 分鐘
- 30 天內合併 PR
- 10
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
sttc/java-sdk 的其他 Issue
-
bug
難度 1/5 1 小時以內 新手友好度 85/100
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
MkCounter.name() returns the class name instead of the counter name, and MkCounters drops the name可能已有人在做 @yegor256 於 20 天前認領。 未關閉bug
sttc/java-sdk#142 · 1 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
wontfix
難度 1/5 1 小時以內 新手友好度 35/100
維護者通常 1 天內回覆
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 68/100
ClouGence/open-cdm#487 · 2 則留言 ·
維護者通常 1 天內回覆
-
security
難度 1/5 1 小時以內 新手友好度 72/100
-
難度 2/5 1-3 小時 新手友好度 62/100
-
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
status: waiting-for-triage type: bug
難度 1/5 1 小時以內 新手友好度 88/100
spring-projects/spring-security#20172 ·
維護者通常 5 天內回覆