/** * Test non-error case just works. * @throws FileNotFoundException * @throws IOException * @throws InterruptedException */ @Test public void testNonErrorCase() throws IOException, InterruptedException { bc.cacheBlock(this.plainKey, this.plainCacheable); doDrainOfOneEntry(this.bc, this.wt, this.q); }
/** * Pass through a too big entry and ensure it is cleared from queues and ramCache. * Manually run the WriterThread. * @throws InterruptedException */ @Test public void testTooBigEntry() throws InterruptedException { Cacheable tooBigCacheable = Mockito.mock(Cacheable.class); Mockito.when(tooBigCacheable.getSerializedLength()).thenReturn(Integer.MAX_VALUE); this.bc.cacheBlock(this.plainKey, tooBigCacheable); doDrainOfOneEntry(this.bc, this.wt, this.q); }
/** * Do IOE. Take the RAMQueueEntry that was on the queue, doctor it to throw exception, then * put it back and process it. * @throws IOException * @throws InterruptedException */ @SuppressWarnings("unchecked") @Test public void testIOE() throws IOException, InterruptedException { this.bc.cacheBlock(this.plainKey, plainCacheable); RAMQueueEntry rqe = q.remove(); RAMQueueEntry spiedRqe = Mockito.spy(rqe); Mockito.doThrow(new IOException("Mocked!")).when(spiedRqe). writeToCache(Mockito.any(), Mockito.any(), Mockito.any()); this.q.add(spiedRqe); doDrainOfOneEntry(bc, wt, q); // Cache disabled when ioes w/o ever healing. assertTrue(!bc.isCacheEnabled()); }
/** * Do Cache full exception * @throws IOException * @throws InterruptedException */ @Test public void testCacheFullException() throws IOException, InterruptedException { this.bc.cacheBlock(this.plainKey, plainCacheable); RAMQueueEntry rqe = q.remove(); RAMQueueEntry spiedRqe = Mockito.spy(rqe); final CacheFullException cfe = new CacheFullException(0, 0); BucketEntry mockedBucketEntry = Mockito.mock(BucketEntry.class); Mockito.doThrow(cfe). doReturn(mockedBucketEntry). when(spiedRqe).writeToCache(Mockito.any(), Mockito.any(), Mockito.any()); this.q.add(spiedRqe); doDrainOfOneEntry(bc, wt, q); }
/** * Pass through a too big entry and ensure it is cleared from queues and ramCache. * Manually run the WriterThread. * @throws InterruptedException */ @Test public void testTooBigEntry() throws InterruptedException { Cacheable tooBigCacheable = Mockito.mock(Cacheable.class); Mockito.when(tooBigCacheable.getSerializedLength()).thenReturn(Integer.MAX_VALUE); this.bc.cacheBlock(this.plainKey, tooBigCacheable); doDrainOfOneEntry(this.bc, this.wt, this.q); }
/** * Test non-error case just works. * @throws FileNotFoundException * @throws IOException * @throws InterruptedException */ @Test public void testNonErrorCase() throws IOException, InterruptedException { bc.cacheBlock(this.plainKey, this.plainCacheable); doDrainOfOneEntry(this.bc, this.wt, this.q); }
/** * Do Cache full exception * @throws IOException * @throws InterruptedException */ @Test public void testCacheFullException() throws IOException, InterruptedException { this.bc.cacheBlock(this.plainKey, plainCacheable); RAMQueueEntry rqe = q.remove(); RAMQueueEntry spiedRqe = Mockito.spy(rqe); final CacheFullException cfe = new CacheFullException(0, 0); BucketEntry mockedBucketEntry = Mockito.mock(BucketEntry.class); Mockito.doThrow(cfe). doReturn(mockedBucketEntry). when(spiedRqe).writeToCache((IOEngine)Mockito.any(), (BucketAllocator)Mockito.any(), (UniqueIndexMap<Integer>)Mockito.any(), (LongAdder) Mockito.any()); this.q.add(spiedRqe); doDrainOfOneEntry(bc, wt, q); }
/** * Do IOE. Take the RAMQueueEntry that was on the queue, doctor it to throw exception, then * put it back and process it. * @throws IOException * @throws InterruptedException */ @SuppressWarnings("unchecked") @Test public void testIOE() throws IOException, InterruptedException { this.bc.cacheBlock(this.plainKey, plainCacheable); RAMQueueEntry rqe = q.remove(); RAMQueueEntry spiedRqe = Mockito.spy(rqe); Mockito.doThrow(new IOException("Mocked!")).when(spiedRqe). writeToCache((IOEngine)Mockito.any(), (BucketAllocator)Mockito.any(), (UniqueIndexMap<Integer>)Mockito.any(), (LongAdder) Mockito.any()); this.q.add(spiedRqe); doDrainOfOneEntry(bc, wt, q); // Cache disabled when ioes w/o ever healing. assertTrue(!bc.isCacheEnabled()); }