/** * Add remove events to the event queue. * @param end * @throws Exception */ public void runRemoveTest( int end ) throws Exception { for ( int i = 0; i <= end; i++ ) { queue.addRemoveEvent( i + ":key" ); } }
public void destroy() if ( isAlive() ) setAlive(false); log.info( "Destroying queue, stats = " + getStatistics() ); log.info( "Destroy was called after queue was destroyed. Doing nothing. Stats = " + getStatistics() );
/** * Constructor for the CacheEventQueue object * <p> * @param listener * @param listenerId * @param cacheName * @param maxFailure * @param waitBeforeRetry */ public CacheEventQueue( ICacheListener<K, V> listener, long listenerId, String cacheName, int maxFailure, int waitBeforeRetry ) { initialize( listener, listenerId, cacheName, maxFailure, waitBeforeRetry, null ); }
/** * Adds an event to the queue. * <p> * @param event */ @Override protected void put( AbstractCacheEvent event ) { if ( log.isDebugEnabled() ) { log.debug( "Event entering Queue for " + getCacheName() + ": " + event ); } queue.offer(event); if ( isWorking() ) { if ( !isAlive() ) { setAlive(true); processorThread = new QProcessor(); processorThread.start(); if ( log.isInfoEnabled() ) { log.info( "Cache event queue created: " + this ); } } } }
/** * Adds put events to the queue. * @param end * @param expectedPutCount * @throws Exception */ public void runPutTest( int end, int expectedPutCount ) throws Exception { for ( int i = 0; i <= end; i++ ) { CacheElement<String, String> elem = new CacheElement<String, String>( "testCache1", i + ":key", i + "data" ); queue.addPutEvent( elem ); } while ( !queue.isEmpty() ) { synchronized ( this ) { System.out.println( "queue is still busy, waiting 250 millis" ); this.wait( 250 ); } } System.out.println( "queue is empty, comparing putCount" ); // this becomes less accurate with each test. It should never fail. If // it does things are very off. assertTrue( "The put count [" + listen.putCount + "] is below the expected minimum threshold [" + expectedPutCount + "]", listen.putCount >= ( expectedPutCount - 1 ) ); }
/** * This method returns semi-structured data on this queue. * <p> * @see org.apache.commons.jcs.engine.behavior.ICacheEventQueue#getStatistics() * @return information on the status and history of the queue */ @Override public IStats getStatistics() { IStats stats = new Stats(); stats.setTypeName( "Cache Event Queue" ); ArrayList<IStatElement<?>> elems = new ArrayList<IStatElement<?>>(); elems.add(new StatElement<Boolean>( "Working", Boolean.valueOf(this.isWorking()) ) ); elems.add(new StatElement<Boolean>( "Alive", Boolean.valueOf(this.isAlive()) ) ); elems.add(new StatElement<Boolean>( "Empty", Boolean.valueOf(this.isEmpty()) ) ); elems.add(new StatElement<Integer>( "Size", Integer.valueOf(this.size()) ) ); stats.setStatElements( elems ); return stats; }
/** * Test setup. Create the static queue to be used by all tests */ @Override public void setUp() { listen = new CacheListenerImpl<String, String>(); queue = new CacheEventQueue<String, String>( listen, 1L, "testCache1", maxFailure, waitBeforeRetry ); queue.setWaitToDieMillis( idleTime ); }
if ( poolType == null || ICacheEventQueue.QueueType.SINGLE == poolType ) eventQueue = new CacheEventQueue<K, V>( listener, listenerId, cacheName, maxFailure, waitBeforeRetry );
/** * Add remove events to the event queue. * @throws Exception */ public void runStopProcessingTest() throws Exception { queue.stopProcessing(); }
log.info( "Destroying queue, stats = " + getStatistics() ); log.info( "Destroy was called after queue was destroyed. Doing nothing. Stats = " + getStatistics() );
/** * Adds put events to the queue. * @param end * @param expectedPutCount * @throws Exception */ public void runPutTest( int end, int expectedPutCount ) throws Exception { for ( int i = 0; i <= end; i++ ) { CacheElement<String, String> elem = new CacheElement<String, String>( "testCache1", i + ":key", i + "data" ); queue.addPutEvent( elem ); } while ( !queue.isEmpty() ) { synchronized ( this ) { System.out.println( "queue is still busy, waiting 250 millis" ); this.wait( 250 ); } } System.out.println( "queue is empty, comparing putCount" ); // this becomes less accurate with each test. It should never fail. If // it does things are very off. assertTrue( "The put count [" + listen.putCount + "] is below the expected minimum threshold [" + expectedPutCount + "]", listen.putCount >= ( expectedPutCount - 1 ) ); }
/** * Test setup. Create the static queue to be used by all tests */ @Override public void setUp() { listen = new CacheListenerImpl<String, String>(); queue = new CacheEventQueue<String, String>( listen, 1L, "testCache1", maxFailure, waitBeforeRetry ); queue.setWaitToDieMillis( idleTime ); }
if ( poolType == null || ICacheEventQueue.QueueType.SINGLE == poolType ) eventQueue = new CacheEventQueue<K, V>( listener, listenerId, cacheName, maxFailure, waitBeforeRetry );
/** * Add remove events to the event queue. * @throws Exception */ public void runStopProcessingTest() throws Exception { queue.stopProcessing(); }
throws Exception while ( !queue.isEmpty() ) queue.addPutEvent( elem ); queue.addPutEvent( elem2 ); while ( !queue.isEmpty() )
/** * Add remove events to the event queue. * @param end * @throws Exception */ public void runRemoveTest( int end ) throws Exception { for ( int i = 0; i <= end; i++ ) { queue.addRemoveEvent( i + ":key" ); } }
/** * Constructor for the CacheEventQueue object * <p> * @param listener * @param listenerId * @param cacheName * @param maxFailure * @param waitBeforeRetry */ public CacheEventQueue( ICacheListener<K, V> listener, long listenerId, String cacheName, int maxFailure, int waitBeforeRetry ) { initialize( listener, listenerId, cacheName, maxFailure, waitBeforeRetry ); }
throws Exception while ( !queue.isEmpty() ) queue.addPutEvent( elem ); queue.addPutEvent( elem2 ); while ( !queue.isEmpty() )