when(mContext.getClientContext()).thenReturn(ClientContext.create(sConf)); when(mContext.getConf()).thenReturn(sConf); PowerMockito.when(mContext.getLocalWorker()).thenReturn(new WorkerNetAddress()); mBlockStore = mock(AlluxioBlockStore.class); PowerMockito.mockStatic(AlluxioBlockStore.class);
WorkerNetAddress worker; if (mPassiveCachingEnabled && mContext.hasLocalWorker()) { // send request to local worker worker = mContext.getLocalWorker(); } else { // send request to data source worker = dataSource;
/** * Tests reading and seeking with no local worker. Nothing should be cached. */ @Test public void testSeekWithNoLocalWorker() throws IOException { // Overrides the get local worker call PowerMockito.when(mContext.getLocalWorker()).thenReturn(null); OpenFilePOptions options = OpenFilePOptions.newBuilder().setReadType(ReadPType.CACHE_PROMOTE).build(); mTestStream = new FileInStream(mStatus, new InStreamOptions(mStatus, options, sConf), mContext); int readAmount = (int) (BLOCK_LENGTH / 2); byte[] buffer = new byte[readAmount]; // read and seek several times mTestStream.read(buffer); assertEquals(readAmount, mInStreams.get(0).getBytesRead()); mTestStream.seek(BLOCK_LENGTH + BLOCK_LENGTH / 2); mTestStream.seek(0); // only reads the read amount, regardless of block source assertEquals(readAmount, mInStreams.get(0).getBytesRead()); assertEquals(0, mInStreams.get(1).getBytesRead()); }