@Test public void givenEmptyCacheWhenFetchingValueExpectNull() { assertNull( cache.get( "1" ) ); }
cache.put( reference.identity().toString(), new CacheState( loadedState.state().toString() ) );
@Test public void givenEmptyCacheWhenFetchingValueExpectNull() { assertNull( cache.get( "1" ) ); }
cache.put( reference.identity().toString(), new CacheState( loadedState.state().toString() ) );
private EntityState fetchCachedState( EntityReference reference, ModuleDescriptor module, Instant currentTime ) { CacheState cacheState = cache.get( reference.identity().toString() ); if( cacheState != null ) { JsonObject state = jsonFactories.readerFactory().createReader( new StringReader( cacheState.string ) ) .readObject(); try { String type = state.getString( JSONKeys.TYPE ); EntityDescriptor entityDescriptor = module.entityDescriptor( type ); String version = state.getString( JSONKeys.VERSION ); Instant modified = Instant.ofEpochMilli( state.getJsonNumber( JSONKeys.MODIFIED ).longValueExact() ); return new JSONEntityState( entityDescriptor.module(), serialization, jsonFactories, version, modified, reference, EntityStatus.LOADED, entityDescriptor, state ); } catch( Exception e ) { // Should not be able to happen, unless internal error in the cache system. throw new EntityStoreException( e ); } } return null; }
private EntityState fetchCachedState( EntityReference reference, ModuleDescriptor module, Instant currentTime ) { CacheState cacheState = cache.get( reference.identity().toString() ); if( cacheState != null ) { JsonObject state = jsonFactories.readerFactory().createReader( new StringReader( cacheState.string ) ) .readObject(); try { String type = state.getString( JSONKeys.TYPE ); EntityDescriptor entityDescriptor = module.entityDescriptor( type ); String version = state.getString( JSONKeys.VERSION ); Instant modified = Instant.ofEpochMilli( state.getJsonNumber( JSONKeys.MODIFIED ).longValueExact() ); return new JSONEntityState( entityDescriptor.module(), serialization, jsonFactories, version, modified, reference, EntityStatus.LOADED, entityDescriptor, state ); } catch( Exception e ) { // Should not be able to happen, unless internal error in the cache system. throw new EntityStoreException( e ); } } return null; }
@Override public synchronized String versionOf( EntityStoreUnitOfWork uow, EntityReference reference ) { CacheState cacheState = cache.get( reference.identity().toString() ); if( cacheState != null ) { return jsonFactories.readerFactory().createReader( new StringReader( cacheState.string ) ).readObject() .getString( JSONKeys.VERSION ); } // Get state try( JsonReader reader = jsonFactories.readerFactory().createReader( mapEntityStore.get( reference ) ) ) { return reader.readObject().getString( JSONKeys.VERSION ); } catch( EntityStoreException ex ) { throw ex; } catch( Exception ex ) { throw new EntityStoreException( ex ); } }
@Test public void givenCacheWithValueWhenDroppingReferenceAndRequestNewCacheAndItsValueExpectItToBeGone() { cache.put( "Habba", "Zout" ); assertEquals( "Zout", cache.get( "Habba" ) ); cachePool.returnCache( cache ); cache = cachePool.fetchCache( "1", String.class ); assertNull( "Value not missing", cache.get( "Habba" ) ); } }
@Override public synchronized String versionOf( EntityStoreUnitOfWork uow, EntityReference reference ) { CacheState cacheState = cache.get( reference.identity().toString() ); if( cacheState != null ) { return jsonFactories.readerFactory().createReader( new StringReader( cacheState.string ) ).readObject() .getString( JSONKeys.VERSION ); } // Get state try( JsonReader reader = jsonFactories.readerFactory().createReader( mapEntityStore.get( reference ) ) ) { return reader.readObject().getString( JSONKeys.VERSION ); } catch( EntityStoreException ex ) { throw ex; } catch( Exception ex ) { throw new EntityStoreException( ex ); } }
@Test public void givenCacheWithValueWhenDroppingReferenceAndRequestNewCacheAndItsValueExpectItToBeGone() { cache.put( "Habba", "Zout" ); assertEquals( "Zout", cache.get( "Habba" ) ); cachePool.returnCache( cache ); cache = cachePool.fetchCache( "1", String.class ); assertNull( "Value not missing", cache.get( "Habba" ) ); } }