Skip to content

Commit

Permalink
Adjust test to not fail if checks cause a slight delay
Browse files Browse the repository at this point in the history
Also make toString() return the same information on repeated calls again
  • Loading branch information
centic9 committed Nov 11, 2022
1 parent 4783886 commit 0498f63
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ private double getPerSecond(AtomicLong bytesWrittenOverall) {

@Override
public String toString() {
long time = System.currentTimeMillis() - start;
//long time = System.currentTimeMillis() - start;
return
"Start: " + start + ", time: " + time + "/" + (double)time / 1000 + ", " +
"Start: " + start + /*", time: " + time + "/" + (double)time / 1000 +*/ ", " +
"Written: " + bytesWrittenOverall.get() + " bytes/" + chunksWrittenOverall.get() + " chunks, " +
String.format("%.2f", getPerSecond(bytesWrittenOverall)) + " bytes/s, " +
String.format("%.2f", getPerSecond(chunksWrittenOverall)) + " chunks/s" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ public void testGetChunksReadPerSec() throws InterruptedException {
getBuffer().add(new Chunk(new byte[] { 1 }, "", tms));
getBuffer().add(new Chunk(new byte[] { 1 }, "", tms));

long start = System.currentTimeMillis();

final double writtenPerSecond = getBuffer().getChunksWrittenPerSecond();
assertTrue("Had: " + writtenPerSecond, Double.isInfinite(writtenPerSecond));
assertEquals(0, getBuffer().getChunksReadPerSecond(), 0);
assertEquals(DEFAULT_CHUNKS_PER_SECOND, getBuffer().getChunksPerSecond(), 0.01);

long start = System.currentTimeMillis();

getBuffer().next();
Thread.sleep(600);
getBuffer().next();
Expand All @@ -86,6 +86,11 @@ public void testGetChunksReadPerSec() throws InterruptedException {

assertTrue(Double.isInfinite(getBuffer().getChunksWrittenPerSecond()));
final double expected = 4 / ((double) (end - start)) * 1000;
System.out.println(
"Having time: " + start + " - " + end + ": " + (end - start) + ": " + getBuffer() +
"\n" + expected +
"\n" + getBuffer().getChunksReadPerSecond());

assertEquals("Having time: " + start + " - " + end + ": " + (end - start) + ": " + getBuffer(),
expected, getBuffer().getChunksReadPerSecond(), 0.01);
assertEquals("Having time: " + start + " - " + end + ": " + (end - start) + ": " + getBuffer(),
Expand Down

0 comments on commit 0498f63

Please sign in to comment.