@Test public void searchWorkflowsByTasks() { workflowService.searchWorkflowsByTasks(0,100,"asc", "*", "*"); verify(mockExecutionService, times(1)).searchWorkflowByTasks(anyString(), anyString(), anyInt(), anyInt(), anyListOf(String.class)); }
@Test public void testSize() { Map<String, Integer> map = new HashMap<>(); map.put("test1", 1); map.put("test2", 2); List<String> list = new ArrayList<String>(); list.add("test1"); list.add("test2"); when(mockTaskService.getTaskQueueSizes(anyListOf(String.class))).thenReturn(map); assertEquals(map, taskResource.size(list)); }
/** * Check handling a connection failure correctly if we get it during the barrier phase */ @Test public void testUnreachableControllerDuringCommit() throws Exception { coordinator = buildNewCoordinator(); // setup the task and spy on it List<String> expected = Arrays.asList("cohort"); final Procedure spy = spy(new Procedure(coordinator, WAKE_FREQUENCY, TIMEOUT, procName, procData, expected)); when(coordinator.createProcedure(any(), eq(procName), eq(procData), anyListOf(String.class))) .thenReturn(spy); // use the passed controller responses IOException cause = new IOException("Failed to reach controller during prepare"); doAnswer(new AcquireBarrierAnswer(procName, new String[] { "cohort" })) .when(controller).sendGlobalBarrierAcquire(eq(spy), eq(procData), anyListOf(String.class)); doThrow(cause).when(controller).sendGlobalBarrierReached(eq(spy), anyListOf(String.class)); // run the operation Procedure task = coordinator.startProcedure(spy.getErrorMonitor(), procName, procData, expected); // and wait for it to finish while(!task.completedLatch.await(WAKE_FREQUENCY, TimeUnit.MILLISECONDS)); verify(spy, atLeastOnce()).receive(any()); verify(coordinator, times(1)).rpcConnectionFailure(anyString(), eq(cause)); verify(controller, times(1)).sendGlobalBarrierAcquire(eq(spy), eq(procData), anyListOf(String.class)); verify(controller, times(1)).sendGlobalBarrierReached(any(), anyListOf(String.class)); }
/** * Check handling a connection failure correctly if we get it during the acquiring phase */ @Test public void testUnreachableControllerDuringPrepare() throws Exception { coordinator = buildNewCoordinator(); // setup the proc List<String> expected = Arrays.asList("cohort"); Procedure proc = new Procedure(coordinator, WAKE_FREQUENCY, TIMEOUT, procName, procData, expected); final Procedure procSpy = spy(proc); when(coordinator.createProcedure(any(), eq(procName), eq(procData), anyListOf(String.class))) .thenReturn(procSpy); // use the passed controller responses IOException cause = new IOException("Failed to reach comms during acquire"); doThrow(cause).when(controller) .sendGlobalBarrierAcquire(eq(procSpy), eq(procData), anyListOf(String.class)); // run the operation proc = coordinator.startProcedure(proc.getErrorMonitor(), procName, procData, expected); // and wait for it to finish while(!proc.completedLatch.await(WAKE_FREQUENCY, TimeUnit.MILLISECONDS)); verify(procSpy, atLeastOnce()).receive(any()); verify(coordinator, times(1)).rpcConnectionFailure(anyString(), eq(cause)); verify(controller, times(1)).sendGlobalBarrierAcquire(procSpy, procData, expected); verify(controller, never()).sendGlobalBarrierReached(any(), anyListOf(String.class)); }
private void callPaint( List<MetricsDuration> durations ) { doCallRealMethod().when( metricsPainter ).paint( anyListOf( MetricsDuration.class ) ); metricsPainter.paint( durations ); }
public void runCoordinatedOperation(Procedure spy, AcquireBarrierAnswer prepareOperation, BarrierAnswer commitOperation, String... cohort) throws Exception { List<String> expected = Arrays.asList(cohort); when(coordinator.createProcedure(any(), eq(procName), eq(procData), anyListOf(String.class))) .thenReturn(spy); // use the passed controller responses doAnswer(prepareOperation).when(controller).sendGlobalBarrierAcquire(spy, procData, expected); doAnswer(commitOperation).when(controller) .sendGlobalBarrierReached(eq(spy), anyListOf(String.class)); // run the operation Procedure task = coordinator.startProcedure(spy.getErrorMonitor(), procName, procData, expected); // and wait for it to finish task.waitForCompleted(); // make sure we mocked correctly prepareOperation.ensureRan(); // we never got an exception InOrder inorder = inOrder(spy, controller); inorder.verify(spy).sendGlobalBarrierStart(); inorder.verify(controller).sendGlobalBarrierAcquire(task, procData, expected); inorder.verify(spy).sendGlobalBarrierReached(); inorder.verify(controller).sendGlobalBarrierReached(eq(task), anyListOf(String.class)); }
@Test public void testUpdateRangeConsolidatesFirst() throws Exception { Change[] ops = new Change[] { Change.update(99, ComponentRenderInfo.createEmpty()), Change.update(100, ComponentRenderInfo.createEmpty()), Change.update(101, ComponentRenderInfo.createEmpty()), Change.updateRange(102, 20, dummyComponentInfos(20)), }; executeOperations(ops); verify(mMockTarget).updateRange(eq(99), eq(3), anyListOf(RenderInfo.class)); verify(mMockTarget).updateRange(eq(102), eq(20), anyListOf(RenderInfo.class)); }
@Test public void testInsertRangeConsolidatesFirst() throws Exception { Change[] ops = new Change[] { Change.insert(99, ComponentRenderInfo.createEmpty()), Change.insert(100, ComponentRenderInfo.createEmpty()), Change.insert(101, ComponentRenderInfo.createEmpty()), Change.insertRange(102, 20, dummyComponentInfos(20)), }; executeOperations(ops); verify(mMockTarget).insertRange(eq(99), eq(3), anyListOf(RenderInfo.class)); verify(mMockTarget).insertRange(eq(102), eq(20), anyListOf(RenderInfo.class)); }
@Test public void testSearchWorkflows() { Workflow workflow = new Workflow(); workflow.setCorrelationId("c123"); WorkflowSummary workflowSummary = new WorkflowSummary(workflow); List<WorkflowSummary> listOfWorkflowSummary = new ArrayList<WorkflowSummary>() {{ add(workflowSummary); }}; SearchResult<WorkflowSummary> searchResult = new SearchResult<WorkflowSummary>(100, listOfWorkflowSummary); when(mockExecutionService.search(anyString(), anyString(), anyInt(), anyInt(), anyListOf(String.class))).thenReturn(searchResult); assertEquals(searchResult, workflowService.searchWorkflows(0,100,"asc", "*", "*")); }
@Test public void testNumReturned() throws MetaException, InvalidOperationException, UnknownDBException, TException { HiveMetaStoreClient msc = mock(HiveMetaStoreClient.class); // create a mocked metastore client that returns 3 table objects every time it is called // will use same size for TableIterable batch fetch size List<Table> threeTables = Arrays.asList(new Table(), new Table(), new Table()); when(msc.getTableObjectsByName(anyString(), anyListOf(String.class))).thenReturn(threeTables); List<String> tableNames = Arrays.asList("a", "b", "c", "d", "e", "f"); TableIterable tIterable = new TableIterable(msc, "dummy", tableNames, threeTables.size()); tIterable.iterator(); Iterator<Table> tIter = tIterable.iterator(); int size = 0; while(tIter.hasNext()) { size++; tIter.next(); } assertEquals("Number of table objects returned", size, tableNames.size()); verify(msc).getTableObjectsByName("dummy", Arrays.asList("a", "b", "c")); verify(msc).getTableObjectsByName("dummy", Arrays.asList("d", "e", "f")); } }
@Test public void shouldEndAfterFailedCheck() { when(mockPredicate.apply(anyListOf(Integer.class))).thenReturn(true); when(mockPredicate.apply(INITIAL_LIST)).thenReturn(false); when(mockFunction.apply(INITIAL_LIST)).thenReturn(LIST); final Repository<List<Integer>> repository = repositoryWithInitialValue(INITIAL_LIST) .observe() .onUpdatesPerLoop() .check(mockPredicate).orEnd(mockFunction) .thenGetFrom(otherListSource) .compile(); updatable.addToObservable(repository); assertThat(repository, has(LIST)); }
@Before public void before() { HepProgramBuilder programBuilder = new HepProgramBuilder(); programBuilder.addRuleInstance(HiveReduceExpressionsWithStatsRule.INSTANCE); planner = new HepPlanner(programBuilder.build()); JavaTypeFactoryImpl typeFactory = new JavaTypeFactoryImpl(); RexBuilder rexBuilder = new RexBuilder(typeFactory); final RelOptCluster optCluster = RelOptCluster.create(planner, rexBuilder); RelDataType rowTypeMock = typeFactory.createStructType(MyRecord.class); Mockito.doReturn(rowTypeMock).when(tableMock).getRowType(); Mockito.doReturn(tableMock).when(schemaMock).getTableForMember(Matchers.any()); statObj = new ColStatistics("_int", "int"); Mockito.doReturn(Lists.newArrayList(statObj)).when(tableMock).getColStat(Matchers.anyListOf(Integer.class), Matchers.eq(false)); Mockito.doReturn(hiveTableMDMock).when(tableMock).getHiveTableMD(); Mockito.doReturn(tableParams).when(hiveTableMDMock).getParameters(); builder = HiveRelFactories.HIVE_BUILDER.create(optCluster, schemaMock); StatsSetupConst.setStatsStateForCreateTable(tableParams, Lists.newArrayList("_int"), StatsSetupConst.TRUE); tableParams.put(StatsSetupConst.ROW_COUNT, "3"); }
/** * Currently we can only handle one procedure at a time. This makes sure we handle that and * reject submitting more. */ @Test public void testThreadPoolSize() throws Exception { ProcedureCoordinator coordinator = buildNewCoordinator(); Procedure proc = new Procedure(coordinator, monitor, WAKE_FREQUENCY, TIMEOUT, procName, procData, expected); Procedure procSpy = spy(proc); Procedure proc2 = new Procedure(coordinator, monitor, WAKE_FREQUENCY, TIMEOUT, procName +"2", procData, expected); Procedure procSpy2 = spy(proc2); when(coordinator.createProcedure(any(), eq(procName), eq(procData), anyListOf(String.class))) .thenReturn(procSpy, procSpy2); coordinator.startProcedure(procSpy.getErrorMonitor(), procName, procData, expected); // null here means second procedure failed to start. assertNull("Coordinator successfully ran two tasks at once with a single thread pool.", coordinator.startProcedure(proc2.getErrorMonitor(), "another op", procData, expected)); }
@Test public void shouldSkipAfterFailedCheck() { when(mockPredicate.apply(anyListOf(Integer.class))).thenReturn(true); when(mockPredicate.apply(INITIAL_LIST)).thenReturn(false); final Repository<List<Integer>> repository = repositoryWithInitialValue(INITIAL_LIST) .observe() .onUpdatesPerLoop() .check(mockPredicate).orSkip() .thenGetFrom(otherListSource) .compile(); updatable.addToObservable(repository); assertThat(repository, has(INITIAL_LIST)); assertThat(updatable, wasNotUpdated()); }
@Test(expected = IOException.class) public void shouldThrowExceptionOnDistcpFailure() throws Exception { Path destination = mock(Path.class); Path source = mock(Path.class); FileSystem fs = mock(FileSystem.class); List<Path> srcPaths = Arrays.asList(source, source); HiveConf conf = mock(HiveConf.class); CopyUtils copyUtils = Mockito.spy(new CopyUtils(null, conf)); mockStatic(FileUtils.class); mockStatic(Utils.class); when(destination.getFileSystem(same(conf))).thenReturn(fs); when(source.getFileSystem(same(conf))).thenReturn(fs); when(FileUtils.distCp(same(fs), anyListOf(Path.class), same(destination), anyBoolean(), eq(null), same(conf), same(ShimLoader.getHadoopShims()))) .thenReturn(false); when(Utils.getUGI()).thenReturn(mock(UserGroupInformation.class)); doReturn(false).when(copyUtils).regularCopy(same(fs), same(fs), anyListOf(ReplChangeManager.FileInfo.class)); copyUtils.doCopy(destination, srcPaths); } }
@Test public void testEventListenersRequestResponse() throws IOException { KaaClientPropertiesState state = new KaaClientPropertiesState(new FilePersistentStorage(), CommonsBase64.getInstance(), KaaClientPropertiesStateTest.getProperties()); EventTransport transport = Mockito.mock(EventTransport.class); ExecutorContext executorContext = Mockito.mock(ExecutorContext.class); Mockito.when(executorContext.getCallbackExecutor()).thenReturn(Executors.newFixedThreadPool(1)); EventManager eventManager = new DefaultEventManager(state, executorContext, transport); List<String> eventFQNs = new ArrayList<String>(); eventFQNs.add("eventFQN1"); FindEventListenersCallback fetchListener = mock(FindEventListenersCallback.class); int requestIdOk = eventManager.findEventListeners(eventFQNs, fetchListener); int requestIdBad = eventManager.findEventListeners(eventFQNs, fetchListener); verify(transport, atLeast(1)).sync(); List<EventListenersResponse> response = new ArrayList<EventListenersResponse>(); response.add(new EventListenersResponse(requestIdOk, new ArrayList<String>(), SyncResponseResultType.SUCCESS)); response.add(new EventListenersResponse(requestIdBad, new ArrayList<String>(), SyncResponseResultType.FAILURE)); eventManager.eventListenersResponseReceived(response); verify(fetchListener, timeout(1000).times(1)).onEventListenersReceived(anyListOf(String.class)); verify(fetchListener, times(1)).onRequestFailed(); }
@Test public void shouldNotSkipAfterPassedCheck() { when(mockPredicate.apply(anyListOf(Integer.class))).thenReturn(true); final Repository<List<Integer>> repository = repositoryWithInitialValue(INITIAL_LIST) .observe() .onUpdatesPerLoop() .check(mockPredicate).orSkip() .thenGetFrom(listSource) .compile(); updatable.addToObservable(repository); assertThat(repository, has(LIST)); assertThat(updatable, wasUpdated()); }
@Test public void testGetWorklfowsMultipleCorrelationId() { Workflow workflow = new Workflow(); workflow.setCorrelationId("c123"); List<Workflow> workflowArrayList = new ArrayList<Workflow>() {{ add(workflow); }}; List<String> correlationIdList = new ArrayList<String>() {{ add("c123"); }}; Map<String, List<Workflow>> workflowMap = new HashMap<>(); workflowMap.put("c123", workflowArrayList); when(mockWorkflowService.getWorkflows(anyString(), anyBoolean(), anyBoolean(), anyListOf(String.class))) .thenReturn(workflowMap); assertEquals(workflowMap, workflowResource.getWorkflows("test", true, true, correlationIdList)); }
@Test public void shouldSearchInvalidUsername() { String username = "invalidUsername"; TextView textView = new TextView(application); textView.setText(username); HttpException mockHttpException = new HttpException(Response.error(404, mock(ResponseBody.class))); when(githubService.publicRepositories(username)) .thenReturn(Observable.<List<Repository>>error(mockHttpException)); mainViewModel.onSearchAction(textView, EditorInfo.IME_ACTION_SEARCH, null); verify(dataListener, never()).onRepositoriesChanged(anyListOf(Repository.class)); assertEquals(mainViewModel.infoMessage.get(), application.getString(R.string.error_username_not_found)); assertEquals(mainViewModel.infoMessageVisibility.get(), View.VISIBLE); assertEquals(mainViewModel.progressVisibility.get(), View.INVISIBLE); assertEquals(mainViewModel.recyclerViewVisibility.get(), View.INVISIBLE); }
@Test public void testConsolidateDifferentTypes() throws Exception { Change[] ops = new Change[] { Change.remove(2), Change.remove(1), Change.update(99, ComponentRenderInfo.createEmpty()), Change.update(100, ComponentRenderInfo.createEmpty()), Change.insert(0, ComponentRenderInfo.createEmpty()), Change.insert(1, ComponentRenderInfo.createEmpty()), Change.update(101, ComponentRenderInfo.createEmpty()), Change.update(99, ComponentRenderInfo.createEmpty()), Change.move(14, 55), }; executeOperations(ops); verify(mMockTarget).deleteRange(1, 2); verify(mMockTarget).updateRange(eq(99), eq(2), anyListOf(RenderInfo.class)); verify(mMockTarget).insertRange(eq(0), eq(2), anyListOf(RenderInfo.class)); verify(mMockTarget).update(101, ops[6].getRenderInfo()); verify(mMockTarget).update(99, ops[7].getRenderInfo()); verify(mMockTarget).move(14,55); }