/** * Set up variables and get BucketCache and WriterThread into state where tests can manually * control the running of WriterThread and BucketCache is empty. * @throws Exception */ @Before public void setUp() throws Exception { // Arbitrary capacity. final int capacity = 16; // Run with one writer thread only. Means there will be one writer queue only too. We depend // on this in below. final int writerThreadsCount = 1; this.bc = new MockBucketCache("offheap", capacity, 1, new int [] {1}, writerThreadsCount, capacity, null, 100/*Tolerate ioerrors for 100ms*/); assertEquals(writerThreadsCount, bc.writerThreads.length); assertEquals(writerThreadsCount, bc.writerQueues.size()); // Get reference to our single WriterThread instance. this.wt = bc.writerThreads[0]; this.q = bc.writerQueues.get(0); wt.disableWriter(); this.plainKey = new BlockCacheKey("f", 0); this.plainCacheable = Mockito.mock(Cacheable.class); assertThat(bc.ramCache.isEmpty(), is(true)); assertTrue(q.isEmpty()); }
@Override public void run() { List<RAMQueueEntry> entries = new ArrayList<>(); try { while (cacheEnabled && writerEnabled) { try { try { // Blocks entries = getRAMQueueEntries(inputQueue, entries); } catch (InterruptedException ie) { if (!cacheEnabled) break; } doDrain(entries); } catch (Exception ioe) { LOG.error("WriterThread encountered error", ioe); } } } catch (Throwable t) { LOG.warn("Failed doing drain", t); } LOG.info(this.getName() + " exiting, cacheEnabled=" + cacheEnabled); }
this.cacheEnabled = true; for (int i = 0; i < writerThreads.length; ++i) { writerThreads[i] = new WriterThread(writerQueues.get(i)); writerThreads[i].setName(threadName + "-BucketCacheWriter-" + i); writerThreads[i].setDaemon(true);
this.cacheEnabled = true; for (int i = 0; i < writerThreads.length; ++i) { writerThreads[i] = new WriterThread(writerQueues.get(i)); writerThreads[i].setName(threadName + "-BucketCacheWriter-" + i); writerThreads[i].setDaemon(true);
/** * Set up variables and get BucketCache and WriterThread into state where tests can manually * control the running of WriterThread and BucketCache is empty. * @throws Exception */ @Before public void setUp() throws Exception { // Arbitrary capacity. final int capacity = 16; // Run with one writer thread only. Means there will be one writer queue only too. We depend // on this in below. final int writerThreadsCount = 1; this.bc = new MockBucketCache("offheap", capacity, 1, new int [] {1}, writerThreadsCount, capacity, null, 100/*Tolerate ioerrors for 100ms*/); assertEquals(writerThreadsCount, bc.writerThreads.length); assertEquals(writerThreadsCount, bc.writerQueues.size()); // Get reference to our single WriterThread instance. this.wt = bc.writerThreads[0]; this.q = bc.writerQueues.get(0); wt.disableWriter(); this.plainKey = new BlockCacheKey("f", 0); this.plainCacheable = Mockito.mock(Cacheable.class); assertThat(bc.ramCache.isEmpty(), is(true)); assertTrue(q.isEmpty()); }
public void run() { List<RAMQueueEntry> entries = new ArrayList<RAMQueueEntry>(); try { while (cacheEnabled && writerEnabled) { try { try { // Blocks entries = getRAMQueueEntries(inputQueue, entries); } catch (InterruptedException ie) { if (!cacheEnabled) break; } doDrain(entries); } catch (Exception ioe) { LOG.error("WriterThread encountered error", ioe); } } } catch (Throwable t) { LOG.warn("Failed doing drain", t); } LOG.info(this.getName() + " exiting, cacheEnabled=" + cacheEnabled); }
/** * Used to shut down the cache -or- turn it off in the case of something * broken. */ private void disableCache() { if (!cacheEnabled) return; cacheEnabled = false; ioEngine.shutdown(); this.scheduleThreadPool.shutdown(); for (int i = 0; i < writerThreads.length; ++i) writerThreads[i].interrupt(); this.ramCache.clear(); if (!ioEngine.isPersistent() || persistencePath == null) { this.backingMap.clear(); } }
private void join() throws InterruptedException { for (int i = 0; i < writerThreads.length; ++i) writerThreads[i].join(); }
/** * Called by the constructor to start the writer threads. Used by tests that need to override * starting the threads. */ @VisibleForTesting protected void startWriterThreads() { for (WriterThread thread : writerThreads) { thread.start(); } }
/** * Only used in test * @throws InterruptedException */ void stopWriterThreads() throws InterruptedException { for (WriterThread writerThread : writerThreads) { writerThread.disableWriter(); writerThread.interrupt(); writerThread.join(); } }
private static void doDrainOfOneEntry(final BucketCache bc, final BucketCache.WriterThread wt, final BlockingQueue<RAMQueueEntry> q) throws InterruptedException { List<RAMQueueEntry> rqes = BucketCache.getRAMQueueEntries(q, new ArrayList<>(1)); wt.doDrain(rqes); assertTrue(q.isEmpty()); assertTrue(bc.ramCache.isEmpty()); assertEquals(0, bc.heapSize()); } }
/** * Used to shut down the cache -or- turn it off in the case of something broken. */ private void disableCache() { if (!cacheEnabled) return; cacheEnabled = false; ioEngine.shutdown(); this.scheduleThreadPool.shutdown(); for (int i = 0; i < writerThreads.length; ++i) writerThreads[i].interrupt(); this.ramCache.clear(); if (!ioEngine.isPersistent() || persistencePath == null) { // If persistent ioengine and a path, we will serialize out the backingMap. this.backingMap.clear(); } }
private void join() throws InterruptedException { for (int i = 0; i < writerThreads.length; ++i) writerThreads[i].join(); }
private static void doDrainOfOneEntry(final BucketCache bc, final BucketCache.WriterThread wt, final BlockingQueue<RAMQueueEntry> q) throws InterruptedException { List<RAMQueueEntry> rqes = BucketCache.getRAMQueueEntries(q, new ArrayList<>(1)); wt.doDrain(rqes); assertTrue(q.isEmpty()); assertTrue(bc.ramCache.isEmpty()); assertEquals(0, bc.heapSize()); } }
/** * Only used in test * @throws InterruptedException */ void stopWriterThreads() throws InterruptedException { for (WriterThread writerThread : writerThreads) { writerThread.disableWriter(); writerThread.interrupt(); writerThread.join(); } }
/** * Called by the constructor to start the writer threads. Used by tests that need to override * starting the threads. */ @VisibleForTesting protected void startWriterThreads() { for (WriterThread thread : writerThreads) { thread.start(); } }