MkCounter.java returns timestamps instead of counter values

オープン 初心者向け
#151 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
88/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java
領域
testing

調査の方向性

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分
マージ済み PR(30日)
10

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

sttc/java-sdk のほかの issue

sttc/java-sdk の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。