@Override public void operate( FlowProcess flowProcess, FunctionCall<CompositeFunction.Context> functionCall ) { TupleEntry arguments = functionCall.getArguments(); Tuple key = TupleHasher.wrapTuple( this.tupleHasher, arguments.selectTupleCopy( groupingFields ) ); Context context = functionCall.getContext(); Tuple[] functorContext = context.lru.get( key ); if( functorContext == null ) { functorContext = new Tuple[ functors.length ]; context.lru.put( key, functorContext ); flowProcess.increment( Cache.Num_Keys_Missed, 1 ); } else { flowProcess.increment( Cache.Num_Keys_Hit, 1 ); } for( int i = 0; i < functors.length; i++ ) { TupleViews.reset( context.arguments[ i ].getTuple(), arguments.getTuple() ); functorContext[ i ] = functors[ i ].aggregate( flowProcess, context.arguments[ i ], functorContext[ i ] ); } }
@Test public void testDirectMappedCacheEviction() { TestCacheEvictionCallBack callBack = new TestCacheEvictionCallBack(); CascadingCache<Object, Object> cache = getDirectMappedCache( 10, callBack ); Collider key = new Collider( "key" ); String value = "value"; cache.put( key, value ); assertEquals( 1, cache.size() ); assertEquals( 0, callBack.evictionCounter ); Collider secondKey = new Collider( "anotherKey" ); cache.put( secondKey, value ); assertEquals( 1, cache.size() ); assertEquals( 1, callBack.evictionCounter ); assertTrue( cache.containsKey( secondKey ) ); assertTrue( cache.containsValue( value ) ); assertSame( value, cache.get( secondKey ) ); assertTrue( callBack.evictedEntries.get( 0 ).getKey().equals( key ) ); assertTrue( callBack.evictedEntries.get( 0 ).getValue().equals( value ) ); }
@Test public void testDirectMappedCache() { CascadingCache<Object, Object> cache = getDirectMappedCache( 10, CacheEvictionCallback.NULL ); assertNotNull( cache ); assertEquals( 0, cache.size() ); String key = "abc"; String value = "def"; cache.put( key, value ); assertEquals( 1, cache.size() ); assertTrue( cache.containsKey( key ) ); assertTrue( cache.containsValue( value ) ); assertSame( value, cache.get( key ) ); Set<Object> keys = cache.keySet(); assertEquals( 1, keys.size() ); assertTrue( keys.contains( key ) ); Collection<Object> values = cache.values(); assertTrue( values.contains( value ) ); cache.clear(); assertEquals( 0, cache.size() ); assertFalse( cache.containsKey( key ) ); assertFalse( cache.containsValue( value ) ); }