@Before public void before() { mMockJobMasterContext = mock(JobMasterContext.class); mMockFileSystemContext = PowerMockito.mock(FileSystemContext.class); when(mMockFileSystemContext.getClientContext()) .thenReturn(ClientContext.create(ServerConfiguration.global())); mMockBlockStore = PowerMockito.mock(AlluxioBlockStore.class); mMockFileSystem = mock(FileSystem.class); mMockUfsManager = mock(UfsManager.class); }
/** * Sets up the file system and the context before a test runs. */ @Before public void before() { mClientContext = ClientContext.create(mConf); mFileContext = PowerMockito.mock(FileSystemContext.class); mFileSystem = new DummyAlluxioFileSystem(mFileContext); mFileSystemMasterClient = PowerMockito.mock(FileSystemMasterClient.class); when(mFileContext.acquireMasterClient()).thenReturn(mFileSystemMasterClient); when(mFileContext.getClientContext()).thenReturn(mClientContext); when(mFileContext.getConf()).thenReturn(mConf); }
@Before public void before() throws Exception { AlluxioConfiguration conf = ConfigurationTestUtils.defaults(); mMockFileSystem = Mockito.mock(FileSystem.class); mMockFileSystemContext = PowerMockito.mock(FileSystemContext.class); when(mMockFileSystemContext.getClientContext()) .thenReturn(ClientContext.create(conf)); when(mMockFileSystemContext.getConf()) .thenReturn(conf); mMockInStream = new MockFileInStream(mMockFileSystemContext, TEST_SOURCE_CONTENTS, conf); when(mMockFileSystem.openFile(new AlluxioURI(TEST_SOURCE))).thenReturn(mMockInStream); mMockOutStream = new MockFileOutStream(mMockFileSystemContext); when(mMockFileSystem.createFile(eq(new AlluxioURI(TEST_DESTINATION)), any(CreateFilePOptions.class))).thenReturn(mMockOutStream); mMockUfsManager = Mockito.mock(UfsManager.class); }
@Before public void before() throws Exception { mClientContext = ClientContext.create(mConf); mContext = PowerMockito.mock(FileSystemContext.class); mAddress = Mockito.mock(WorkerNetAddress.class); mClient = mock(BlockWorkerClient.class); mRequestObserver = mock(ClientCallStreamObserver.class); PowerMockito.when(mContext.getClientContext()).thenReturn(mClientContext); PowerMockito.when(mContext.getConf()).thenReturn(mConf); PowerMockito.when(mContext.acquireBlockWorkerClient(mAddress)).thenReturn(mClient); PowerMockito.doNothing().when(mContext).releaseBlockWorkerClient(mAddress, mClient); PowerMockito.when(mClient.writeBlock(any(StreamObserver.class))).thenReturn(mRequestObserver); PowerMockito.when(mRequestObserver.isReady()).thenReturn(true); }
@Before public void before() throws Exception { mContext = PowerMockito.mock(FileSystemContext.class); mAddress = mock(WorkerNetAddress.class); mClient = mock(BlockWorkerClient.class); mRequestObserver = mock(ClientCallStreamObserver.class); PowerMockito.when(mContext.acquireBlockWorkerClient(mAddress)).thenReturn(mClient); PowerMockito.when(mContext.getClientContext()) .thenReturn(ClientContext.create(mConf)); PowerMockito.when(mContext.getConf()).thenReturn(mConf); PowerMockito.doNothing().when(mContext).releaseBlockWorkerClient(mAddress, mClient); PowerMockito.when(mClient.writeBlock(any(StreamObserver.class))).thenReturn(mRequestObserver); PowerMockito.when(mRequestObserver.isReady()).thenReturn(true); }
@Before public void before() throws Exception { mMasterClient = PowerMockito.mock(BlockMasterClient.class); mWorkerClient = PowerMockito.mock(BlockWorkerClient.class); mContext = PowerMockito.mock(FileSystemContext.class); when(mContext.acquireBlockMasterClientResource()) .thenReturn(new DummyCloseableResource<>(mMasterClient)); when(mContext.getClientContext()).thenReturn(ClientContext.create(sConf)); when(mContext.getConf()).thenReturn(sConf); mLocalAddr = new WorkerNetAddress().setHost(NetworkAddressUtils.getLocalHostName( (int) sConf.getMs(PropertyKey.NETWORK_HOST_RESOLUTION_TIMEOUT_MS))); mBlockStore = new AlluxioBlockStore(mContext, TieredIdentityFactory.fromString("node=" + WORKER_HOSTNAME_LOCAL, sConf)); when(mContext.acquireBlockWorkerClient(any(WorkerNetAddress.class))) .thenReturn(mWorkerClient); mStreamObserver = PowerMockito.mock(ClientCallStreamObserver.class); when(mWorkerClient.writeBlock(any(StreamObserver.class))) .thenReturn(mStreamObserver); when(mWorkerClient.openLocalBlock(any(StreamObserver.class))) .thenReturn(mStreamObserver); when(mStreamObserver.isReady()).thenReturn(true); }
@Before public void before() throws Exception { mMockJobMasterContext = Mockito.mock(JobMasterContext.class); mMockFileSystem = PowerMockito.mock(FileSystem.class); mMockBlockStore = PowerMockito.mock(AlluxioBlockStore.class); mMockFsContext = PowerMockito.mock(FileSystemContext.class); PowerMockito.mockStatic(AlluxioBlockStore.class); PowerMockito.when(AlluxioBlockStore.create(Mockito.any(FileSystemContext.class))) .thenReturn(mMockBlockStore); Mockito.when(mMockBlockStore.getAllWorkers()).thenReturn(BLOCK_WORKERS); PowerMockito.when(mMockFsContext.getClientContext()) .thenReturn(ClientContext.create(ServerConfiguration.global())); PowerMockito.when(mMockFsContext.getConf()) .thenReturn(ServerConfiguration.global()); }
@Test public void createShortCircuitDisabled() throws Exception { try (Closeable c = new ConfigurationRule(PropertyKey.USER_SHORT_CIRCUIT_ENABLED, "false", mConf) .toResource()) { WorkerNetAddress dataSource = new WorkerNetAddress(); when(mMockContext.getClientContext()).thenReturn(ClientContext.create(mConf)); BlockInStream.BlockInStreamSource dataSourceType = BlockInStream.BlockInStreamSource.LOCAL; BlockInStream stream = BlockInStream.create(mMockContext, mInfo, dataSource, dataSourceType, mOptions); Assert.assertFalse(stream.isShortCircuit()); } }
@Before public void before() throws Exception { mContext = PowerMockito.mock(FileSystemContext.class); when(mContext.getClientContext()) .thenReturn(ClientContext.create(ConfigurationTestUtils.defaults())); when(mContext.getConf()).thenReturn(ConfigurationTestUtils.defaults()); mAddress = mock(WorkerNetAddress.class); ReadRequest readRequest = ReadRequest.newBuilder().setBlockId(BLOCK_ID).setChunkSize(CHUNK_SIZE).build(); mFactory = new GrpcDataReader.Factory(mContext, mAddress, readRequest); mClient = mock(BlockWorkerClient.class); mRequestObserver = mock(ClientCallStreamObserver.class); when(mContext.acquireBlockWorkerClient(mAddress)).thenReturn(mClient); PowerMockito.doNothing().when(mContext).releaseBlockWorkerClient(mAddress, mClient); when(mClient.readBlock(any(StreamObserver.class))).thenReturn(mRequestObserver); when(mRequestObserver.isReady()).thenReturn(true); }
@Before public void before() throws Exception { BlockWorkerClient workerClient = PowerMockito.mock(BlockWorkerClient.class); ClientCallStreamObserver requestObserver = PowerMockito.mock(ClientCallStreamObserver.class); when(requestObserver.isReady()).thenReturn(true); when(workerClient.openLocalBlock(any(StreamObserver.class))) .thenAnswer(new Answer() { public Object answer(InvocationOnMock invocation) { StreamObserver<OpenLocalBlockResponse> observer = invocation.getArgumentAt(0, StreamObserver.class); observer.onNext(OpenLocalBlockResponse.newBuilder().setPath("/tmp").build()); observer.onCompleted(); return requestObserver; } }); mMockContext = PowerMockito.mock(FileSystemContext.class); PowerMockito.when(mMockContext.acquireBlockWorkerClient(Matchers.any(WorkerNetAddress.class))) .thenReturn(workerClient); PowerMockito.when(mMockContext.getClientContext()).thenReturn(ClientContext.create(mConf)); PowerMockito.when(mMockContext.getConf()).thenReturn(mConf); PowerMockito.doNothing().when(mMockContext) .releaseBlockWorkerClient(Matchers.any(WorkerNetAddress.class), Matchers.any(BlockWorkerClient.class)); mInfo = new BlockInfo().setBlockId(1); mOptions = new InStreamOptions(new URIStatus(new FileInfo().setBlockIds(Collections .singletonList(1L))), mConf); }
when(mContext.getClientContext()).thenReturn(ClientContext.create(sConf)); when(mContext.getConf()).thenReturn(sConf); PowerMockito.when(mContext.getLocalWorker()).thenReturn(new WorkerNetAddress());