/**
Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved.
Contact:
SYSTAP, LLC DBA Blazegraph
2501 Calvert ST NW #106
Washington, DC 20008
licenses@blazegraph.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Created on Sep 15, 2007
*/
package com.bigdata.util;
import junit.framework.TestCase;
/**
* Test suite for {@link HybridTimestampFactory}.
*
* @todo test ctor correct acceptance and correct rejection and internally
* computed fields.
*
* @todo test with all legal ctor values for counterBits and plot the #of
* distinct timestamps per millisecond as a function of counterBits.
*
* @author <a href="mailto:thompsonbry@users.sourceforge.net">Bryan Thompson</a>
* @version $Id$
*/
public class TestHybridTimestampFactory extends TestCase {
/**
*
*/
public TestHybridTimestampFactory() {
super();
}
/**
* @param arg0
*/
public TestHybridTimestampFactory(String arg0) {
super(arg0);
}
/**
* Test verifies that timestamps are always distinct from the last generated
* timestamp as generated by {@link HybridTimestampFactory#nextMillis()} and
* notes the actual granularity of the generated timestamps.
*/
public void test_nextTimestamp2() {
final int limit = 100000;
HybridTimestampFactory timestampFactory = new HybridTimestampFactory(10);
final long begin = System.currentTimeMillis();
long lastTimestamp = begin - 1;
long timestamp;
for( int i=0; i<limit; i++ ) {
timestamp = timestampFactory.nextTimestamp();
if (timestamp == lastTimestamp)
fail("Same timestamp?");
if (timestamp < lastTimestamp)
fail("Time goes backwards?");
lastTimestamp = timestamp;
}
long elapsed = System.currentTimeMillis() - begin;
System.err.println("Generated " + limit + " timestamps in " + elapsed
+ " milliseconds: ts/ms: " + limit / (double) elapsed);
System.err.println("The #of times the factory invoked Thread.sleep(): "
+ timestampFactory.getSleepCounter());
}
}