@Override public long getMinTime() { final long minimumAllowed = ( long ) (2.5 * graphFig.getShardCacheTimeout()); final long minDelta = graphFig.getShardMinDelta(); if ( minDelta < minimumAllowed ) { throw new GraphRuntimeException( String .format( "You must configure the property %s to be >= 2 x %s. Otherwise you risk losing data", GraphFig.SHARD_MIN_DELTA, GraphFig.SHARD_CACHE_TIMEOUT ) ); } return timeService.getCurrentTime() - minDelta; }
/** * This is a race condition. We could re-init the shard while another thread is reading it. This is fine, the read * doesn't have to be precise. The algorithm accounts for stale data. */ private void updateCache() { if ( this.refreshExecutors != null ) { this.refreshExecutors.shutdown(); } this.refreshExecutors = MoreExecutors .listeningDecorator( Executors.newScheduledThreadPool( graphFig.getShardCacheRefreshWorkerCount() ) ); this.graphs = CacheBuilder.newBuilder() //we want to asynchronously load new values for existing ones, that way we wont' have to //wait for a trip to cassandra .refreshAfterWrite( graphFig.getShardCacheTimeout(), TimeUnit.MILLISECONDS ) //set a static cache entry size here .maximumSize(graphFig.getShardCacheSize()) //set our shard loader .build( new ShardCacheLoader() ); }
private GraphFig getFigMock() { final GraphFig graphFig = mock( GraphFig.class ); when( graphFig.getShardCacheSize() ).thenReturn( 1000l ); when( graphFig.getShardCacheTimeout() ).thenReturn( 30000l ); return graphFig; } }
@Before public void setup() { scope = mock( ApplicationScope.class ); Id orgId = mock( Id.class ); when( orgId.getType() ).thenReturn( "organization" ); when( orgId.getUuid() ).thenReturn( UUIDGenerator.newTimeUUID() ); when( scope.getApplication() ).thenReturn( orgId ); graphFig = mock( GraphFig.class ); when( graphFig.getShardCacheSize() ).thenReturn( 10000l ); when( graphFig.getShardSize() ).thenReturn( 20000l ); final long timeout = 30000; when( graphFig.getShardCacheTimeout() ).thenReturn( timeout ); when( graphFig.getShardMinDelta() ).thenReturn( ( long ) (timeout * 2.5) ); }
@Test public void minTime() { final ShardGroupCompaction shardGroupCompaction = mock( ShardGroupCompaction.class ); final EdgeShardSerialization edgeShardSerialization = mock( EdgeShardSerialization.class ); final EdgeColumnFamilies edgeColumnFamilies = mock( EdgeColumnFamilies.class ); final ShardedEdgeSerialization shardedEdgeSerialization = mock( ShardedEdgeSerialization.class ); final TimeService timeService = mock( TimeService.class ); final NodeShardCache nodeShardCache = mock( NodeShardCache.class); NodeShardAllocation approximation = new NodeShardAllocationImpl( edgeShardSerialization, edgeColumnFamilies, shardedEdgeSerialization, timeService, graphFig, shardGroupCompaction, nodeShardCache ); final long timeservicetime = System.currentTimeMillis(); when( timeService.getCurrentTime() ).thenReturn( timeservicetime ); final long expected = ( long ) (timeservicetime - 2.5 * graphFig.getShardCacheTimeout()); final long returned = approximation.getMinTime(); assertEquals( "Correct time was returned", expected, returned ); }
when( graphFig.getShardCacheTimeout() ).thenReturn( 30000l );
final long returnTime = System.currentTimeMillis() + graphFig.getShardCacheTimeout() * 2;
final long timeoutDelta = graphFig.getShardCacheTimeout();
final long minExecutionTime = graphFig.getShardMinDelta() + graphFig.getShardCacheTimeout() + 120000;
assertTrue( "Shard cache mocked", graphFig.getShardCacheTimeout() > 0 );
final long minExecutionTime = graphFig.getShardMinDelta() + graphFig.getShardCacheTimeout();
final long minExecutionTime = graphFig.getShardMinDelta() + graphFig.getShardCacheTimeout();