/*
 * Copyright Terracotta, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.ehcache.core.spi.time;

import org.junit.After;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class TickingTimeSourceTest {

  private final TickingTimeSource tickingTimeSource = new TickingTimeSource(1L, 1000L);

  @After
  public void after() {
    tickingTimeSource.stop();
  }

  @Test
  public void getTimeMillis() {

    // Hard to test but let's just say...
    long currentTime = System.currentTimeMillis();
    tickingTimeSource.start(null);

    long actualTime = tickingTimeSource.getTimeMillis();

    // ... that time should start now...
    assertThat(actualTime).isGreaterThanOrEqualTo(currentTime);

    // ... and increase
    for (int i = 0; i < 1_000_000; i++) {
      if(tickingTimeSource.getTimeMillis() > actualTime) {
        break;
      }
    }

    assertThat(tickingTimeSource.getTimeMillis()).isGreaterThan(actualTime);
  }
}

@@ -1293,42 +1293,173 @@
     
-for (int i = 0; i %3C 1_000_000; i++
+long end = System.currentTimeMillis() + 30_000; // 30 seconds should be way way enough to at least tick of one millisecond%0A    while(System.currentTimeMillis() %3C end
 ) %7B%0A

Stop TickingTimeSourceTest based on time, not on loops