package com.proofpoint.testing;

import com.google.common.base.Ticker;

import java.util.concurrent.TimeUnit;

import static com.google.common.base.Preconditions.checkArgument;

public class TestingTicker
        extends Ticker
{
    private long time;

    @Override
    public long read()
    {
        return time;
    }

    /**
     * @deprecated Use {@link #elapseTime(long, TimeUnit)}
     */
    @Deprecated
    public void increment(long delta, TimeUnit unit)
    {
        checkArgument(delta >= 0, "delta is negative");
        time += unit.toNanos(delta);
    }

    /**
     * Advance time by the given quantum.
     *
     * @param quantum the amount of time to advance
     * @param timeUnit the unit of the quantum amount
     */
    public void elapseTime(long quantum, TimeUnit timeUnit)
    {
        checkArgument(quantum >= 0, "quantum is negative");
        time += timeUnit.toNanos(quantum);
    }

    public void elapseTimeNanosecondBefore(long quantum, TimeUnit timeUnit)
    {
        checkArgument(quantum > 0, "quantum is non-positive");
        time += timeUnit.toNanos(quantum) - 1;
    }
}

@@ -102,16 +102,63 @@
 imeUnit;
+%0Aimport java.util.concurrent.atomic.AtomicLong;
 %0A%0Aimport
@@ -286,17 +286,48 @@
 ate 
-long time
+final AtomicLong time = new AtomicLong()
 ;%0A%0A 
@@ -387,16 +387,22 @@
 urn time
+.get()
 ;%0A    %7D%0A
@@ -620,20 +620,27 @@
     time
- += 
+.getAndAdd(
 unit.toN
@@ -650,16 +650,17 @@
 s(delta)
+)
 ;%0A    %7D%0A
@@ -961,36 +961,43 @@
 %22);%0A        time
- += 
+.getAndAdd(
 timeUnit.toNanos
@@ -1005,16 +1005,17 @@
 quantum)
+)
 ;%0A    %7D%0A
@@ -1176,12 +1176,19 @@
 time
- += 
+.getAndAdd(
 time
@@ -1212,16 +1212,17 @@
 tum) - 1
+)
 ;%0A    %7D%0A

Make TestingTicker thread safe