-
Notifications
You must be signed in to change notification settings - Fork 62
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
Showing
1 changed file
with
37 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.astraea.cost; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class PeriodicTest extends Periodic<Map<Integer, Double>> { | ||
private double brokerValue = 0.0; | ||
|
||
@Test | ||
void testTryUpdate() { | ||
var broker1 = tryUpdate(this::testMap); | ||
Assertions.assertEquals(broker1.get(0), 0.0); | ||
var broker2 = tryUpdate(this::testMap); | ||
Assertions.assertEquals(broker2.get(0), 0.0); | ||
sleep(1); | ||
broker2 = tryUpdate(this::testMap); | ||
Assertions.assertEquals(broker2.get(0), 1.0); | ||
} | ||
|
||
Map<Integer, Double> testMap() { | ||
var broker = new HashMap<Integer, Double>(); | ||
broker.put(0, brokerValue); | ||
brokerValue++; | ||
return broker; | ||
} | ||
|
||
private static void sleep(int seconds) { | ||
try { | ||
TimeUnit.SECONDS.sleep(seconds); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |