@Test public void givenLoooongCacheNameWhenFetchingCacheExpectOk() { Random random = new Random(); StringBuilder longName = new StringBuilder(); for( int i = 0; i < 10000; i++ ) { longName.append( (char) ( random.nextInt( 26 ) + 65 ) ); } cache = cachePool.fetchCache( longName.toString(), String.class ); }
@Override public void tearDownJSONMapES() throws Exception { if( caching != null ) { caching.returnCache( cache ); cache = null; } }
@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" ) ); } }
@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" ) ); } }
@Test public void givenLoooongCacheNameWhenFetchingCacheExpectOk() { Random random = new Random(); StringBuilder longName = new StringBuilder(); for( int i = 0; i < 10000; i++ ) { longName.append( (char) ( random.nextInt( 26 ) + 65 ) ); } cache = cachePool.fetchCache( longName.toString(), String.class ); }
@Override public void tearDownJSONMapES() throws Exception { if( caching != null ) { caching.returnCache( cache ); cache = null; } }
@Override public void setUpJSONMapES() throws Exception { uuid = descriptor.identity() + "-" + UUID.randomUUID().toString(); if( caching != null ) { cache = caching.fetchCache( uuid, CacheState.class ); } else { cache = new NullCache<>(); } }
@Override public void setUpJSONMapES() throws Exception { uuid = descriptor.identity() + "-" + UUID.randomUUID().toString(); if( caching != null ) { cache = caching.fetchCache( uuid, CacheState.class ); } else { cache = new NullCache<>(); } }
@Test public void givenInvalidCacheNameWhenFetchingCacheExpectIllegalArgumentException() { try { cache = cachePool.fetchCache( "", String.class ); fail( "Expected " + IllegalArgumentException.class.getSimpleName() ); } catch( IllegalArgumentException e ) { // expected } }
@Test public void givenInvalidCacheNameWhenFetchingCacheExpectIllegalArgumentException() { try { cache = cachePool.fetchCache( "", String.class ); fail( "Expected " + IllegalArgumentException.class.getSimpleName() ); } catch( IllegalArgumentException e ) { // expected } }
@Override public void setUp() throws Exception { super.setUp(); cachePool = module.instance().findService( CachePool.class ).get(); cache = cachePool.fetchCache( "1", String.class ); }
@Override public void setUp() throws Exception { super.setUp(); cachePool = module.instance().findService( CachePool.class ).get(); cache = cachePool.fetchCache( "1", String.class ); }
@Test public void givenNullKeyWhenFetchingCacheExpectConstraintViolationException() { try { cache = cachePool.fetchCache( null, String.class ); fail( "Expected " + ConstraintViolationException.class.getSimpleName() ); } catch( ConstraintViolationException e ) { // expected Collection<ValueConstraintViolation> violations = e.constraintViolations(); assertEquals( 1, violations.size() ); ValueConstraintViolation violation = violations.iterator().next(); assertEquals( "not optional", violation.constraint().toString() ); assertThat( violation.name(), anyOf(equalTo("cacheId"), equalTo( "arg0" )) ); // depends on whether -parameters was given at compile time. } }
@Test public void givenNullKeyWhenFetchingCacheExpectConstraintViolationException() { try { cache = cachePool.fetchCache( null, String.class ); fail( "Expected " + ConstraintViolationException.class.getSimpleName() ); } catch( ConstraintViolationException e ) { // expected Collection<ValueConstraintViolation> violations = e.constraintViolations(); assertEquals( 1, violations.size() ); ValueConstraintViolation violation = violations.iterator().next(); assertEquals( "not optional", violation.constraint().toString() ); assertThat( violation.name(), anyOf(equalTo("cacheId"), equalTo( "arg0" )) ); // depends on whether -parameters was given at compile time. } }