@Test public void setupInternalStateOnObjectCreation() throws IOException, TezException { when(dagStatus.getState()).thenReturn(DAGStatus.State.RUNNING); when(dagClient.getVertexStatus(eq(MAPPER), anySet())).thenReturn(succeeded); when(dagClient.getVertexStatus(eq(REDUCER), anySet())).thenReturn(running); TezProgressMonitor monitor = new TezProgressMonitor(dagClient, dagStatus, new ArrayList<BaseWork>(), progressMap(), console, Long.MAX_VALUE); verify(dagClient).getVertexStatus(eq(MAPPER), isNull(Set.class)); verify(dagClient).getVertexStatus(eq(REDUCER), isNull(Set.class)); verifyNoMoreInteractions(dagClient); assertThat(monitor.vertexStatusMap.keySet(), hasItems(MAPPER, REDUCER)); assertThat(monitor.vertexStatusMap.get(MAPPER), is(sameInstance(succeeded))); assertThat(monitor.vertexStatusMap.get(REDUCER), is(sameInstance(running))); assertThat(monitor.progressCountsMap.keySet(), hasItems(MAPPER, REDUCER)); TezProgressMonitor.VertexProgress expectedMapperState = new TezProgressMonitor.VertexProgress(2, 1, 3, 4, 5, DAGStatus.State.RUNNING); assertThat(monitor.progressCountsMap.get(MAPPER), is(equalTo(expectedMapperState))); TezProgressMonitor.VertexProgress expectedReducerState = new TezProgressMonitor.VertexProgress(3, 2, 1, 0, 1, DAGStatus.State.RUNNING); assertThat(monitor.progressCountsMap.get(REDUCER), is(equalTo(expectedReducerState))); }
photosList.setPages(page + 1); when(photosetsInterface.getPhotos(anyString(), anySet(), anyInt(), anyInt(), anyInt())) .thenReturn(photosList);
@Test public void testRequestWithSerializationException() throws IOException { FullHttpRequest request = createQueryRequest("?points=10&from=1&to=2", createRequestBody(1)); ArgumentCaptor<FullHttpResponse> argument = ArgumentCaptor.forClass(FullHttpResponse.class); String message = "mock exception message"; when(serializer.transformRollupData(anyMap(), anySet())).thenThrow(new SerializationException(message)); handler.handle(context, request); verify(channel).write(argument.capture()); String errorResponseBody = argument.getValue().content().toString(Charset.defaultCharset()); ErrorResponse errorResponse = getErrorResponse(errorResponseBody); assertEquals("Number of errors invalid", 1, errorResponse.getErrors().size()); assertEquals("Invalid error message", message, errorResponse.getErrors().get(0).getMessage()); assertEquals("Invalid tenant", TENANT, errorResponse.getErrors().get(0).getTenantId()); assertEquals("Invalid status", HttpResponseStatus.INTERNAL_SERVER_ERROR, argument.getValue().getStatus()); }
@Test public void testGetMasterRelation() { // given Mockito.when(resourceEntity.getMasterRelation(Matchers.any(ResourceEntity.class), Matchers.anySet())).thenCallRealMethod(); final int slaveResourceId = 21; final Set<ConsumedResourceRelationEntity> relations = new HashSet<ConsumedResourceRelationEntity>(); final ConsumedResourceRelationEntity resourceRelation = Mockito.mock(ConsumedResourceRelationEntity.class); relations.add(resourceRelation); final ResourceEntity slaveResource = Mockito.mock(ResourceEntity.class); Mockito.when(slaveResource.getId()).thenReturn(slaveResourceId); Mockito.when(resourceRelation.getSlaveResource()).thenReturn(slaveResource); // when final AbstractResourceRelationEntity result = resourceEntity.getMasterRelation(slaveResource, relations); // then assertEquals(resourceRelation, result); }
@Test @SuppressWarnings("unchecked") public void testMax0EvaluateFailed() { final Map<String, Integer> count = new HashMap<String, Integer>(1) {{ put(CANDIDATE_ROLE1, 1); }}; doReturn(count).when(tested).countLabels(any(Graph.class), anySet()); when(context.getCandidate()).thenReturn(Optional.empty()); when(context.getOperation()).thenReturn(Optional.empty()); final RuleViolations violations = tested.evaluate(RULE_MAX_0, context); assertNotNull(violations); assertTrue(violations.violations(RuleViolation.Type.WARNING).iterator().hasNext()); } }
@Test @SuppressWarnings("unchecked") public void testMax0Failed() { final Map<String, Integer> count = new HashMap<String, Integer>(1) {{ put(CANDIDATE_ROLE1, 0); }}; doReturn(count).when(tested).countLabels(any(Graph.class), anySet()); when(context.getCandidate()).thenReturn(Optional.of(candidate)); when(context.getOperation()).thenReturn(Optional.of(CardinalityContext.Operation.ADD)); final RuleViolations violations = tested.evaluate(RULE_MAX_0, context); assertNotNull(violations); assertTrue(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext()); }
@Test public void testGetRelationById() { // given Mockito.when(resourceEntity.getRelationById(Matchers.anyInt(), Matchers.anySet())).thenCallRealMethod(); final int slaveResourceId = 21; final Set<ConsumedResourceRelationEntity> relations = new HashSet<ConsumedResourceRelationEntity>(); final ConsumedResourceRelationEntity resourceRelation = Mockito.mock(ConsumedResourceRelationEntity.class); relations.add(resourceRelation); final ResourceEntity slaveResource = Mockito.mock(ResourceEntity.class); Mockito.when(slaveResource.getId()).thenReturn(slaveResourceId); Mockito.when(resourceRelation.getSlaveResource()).thenReturn(slaveResource); // when final AbstractResourceRelationEntity result = resourceEntity.getRelationById(slaveResourceId, relations); // then assertEquals(resourceRelation, result); }
@Test @SuppressWarnings("unchecked") public void testMin1EvaluateFailed() { final Map<String, Integer> count = new HashMap<String, Integer>(1) {{ put(CANDIDATE_ROLE1, 0); }}; doReturn(count).when(tested).countLabels(any(Graph.class), anySet()); when(context.getCandidate()).thenReturn(Optional.empty()); when(context.getOperation()).thenReturn(Optional.empty()); final RuleViolations violations = tested.evaluate(RULE_MIN_1, context); assertNotNull(violations); assertTrue(violations.violations(RuleViolation.Type.WARNING).iterator().hasNext()); }
@Test @SuppressWarnings("unchecked") public void testMax0EvaluateSuccess() { final Map<String, Integer> count = new HashMap<String, Integer>(1) {{ put(CANDIDATE_ROLE1, 0); }}; doReturn(count).when(tested).countLabels(any(Graph.class), anySet()); when(context.getCandidate()).thenReturn(Optional.empty()); when(context.getOperation()).thenReturn(Optional.empty()); final RuleViolations violations = tested.evaluate(RULE_MAX_0, context); assertNotNull(violations); assertFalse(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext()); }
@Test @SuppressWarnings("unchecked") public void testMin1AddOk() { final Map<String, Integer> count = new HashMap<String, Integer>(1) {{ put(CANDIDATE_ROLE1, 0); }}; doReturn(count).when(tested).countLabels(any(Graph.class), anySet()); when(context.getCandidate()).thenReturn(Optional.of(candidate)); when(context.getOperation()).thenReturn(Optional.of(CardinalityContext.Operation.ADD)); final RuleViolations violations = tested.evaluate(RULE_MIN_1, context); assertNotNull(violations); assertFalse(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext()); }
@Test @SuppressWarnings("unchecked") public void testMin1DeleteOk() { final Map<String, Integer> count = new HashMap<String, Integer>(1) {{ put(CANDIDATE_ROLE1, 2); }}; doReturn(count).when(tested).countLabels(any(Graph.class), anySet()); when(context.getCandidate()).thenReturn(Optional.of(candidate)); when(context.getOperation()).thenReturn(Optional.of(CardinalityContext.Operation.DELETE)); final RuleViolations violations = tested.evaluate(RULE_MIN_1, context); assertNotNull(violations); assertFalse(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext()); }
@Test @SuppressWarnings("unchecked") public void testMin1DeleteFailed() { final Map<String, Integer> count = new HashMap<String, Integer>(2) {{ put(CANDIDATE_ROLE1, 1); put(CANDIDATE_ROLE2, 0); }}; doReturn(count).when(tested).countLabels(any(Graph.class), anySet()); when(context.getCandidate()).thenReturn(Optional.of(candidate)); when(context.getOperation()).thenReturn(Optional.of(CardinalityContext.Operation.DELETE)); final RuleViolations violations = tested.evaluate(RULE_MIN_1, context); assertNotNull(violations); assertTrue(violations.violations(RuleViolation.Type.WARNING).iterator().hasNext()); }
@Test @SuppressWarnings("unchecked") public void testMax1Ok() { final Map<String, Integer> count = new HashMap<String, Integer>(2) {{ put(CANDIDATE_ROLE1, 0); put(CANDIDATE_ROLE2, 0); }}; doReturn(count).when(tested).countLabels(any(Graph.class), anySet()); when(context.getCandidate()).thenReturn(Optional.of(candidate)); when(context.getOperation()).thenReturn(Optional.of(CardinalityContext.Operation.ADD)); final RuleViolations violations = tested.evaluate(RULE_MAX_1, context); assertNotNull(violations); assertFalse(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext()); }
@Test @SuppressWarnings("unchecked") public void testEvaluateSuccess() { final Map<String, Integer> count = new HashMap<String, Integer>(2) {{ put(CANDIDATE_ROLE1, 0); put(CANDIDATE_ROLE2, 0); }}; doReturn(count).when(tested).countLabels(any(Graph.class), anySet()); when(context.getCandidate()).thenReturn(Optional.of(candidate)); when(context.getOperation()).thenReturn(Optional.of(CardinalityContext.Operation.ADD)); final RuleViolations violations = tested.evaluate(RULE_NO_LIMIT, context); assertNotNull(violations); assertFalse(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext()); }
@Test @SuppressWarnings("unchecked") public void testMax1Failed() { final Map<String, Integer> count = new HashMap<String, Integer>(2) {{ put(CANDIDATE_ROLE1, 1); put(CANDIDATE_ROLE2, 0); }}; doReturn(count).when(tested).countLabels(any(Graph.class), anySet()); when(context.getCandidate()).thenReturn(Optional.of(candidate)); when(context.getOperation()).thenReturn(Optional.of(CardinalityContext.Operation.ADD)); final RuleViolations violations = tested.evaluate(RULE_MAX_1, context); assertNotNull(violations); assertTrue(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext()); }
@Test @SuppressWarnings("unchecked") public void testEvaluateSuccessAgain() { final Map<String, Integer> count = new HashMap<String, Integer>(2) {{ put(CANDIDATE_ROLE1, 100); put(CANDIDATE_ROLE2, 0); }}; doReturn(count).when(tested).countLabels(any(Graph.class), anySet()); when(context.getCandidate()).thenReturn(Optional.of(candidate)); when(context.getOperation()).thenReturn(Optional.of(CardinalityContext.Operation.ADD)); final RuleViolations violations = tested.evaluate(RULE_NO_LIMIT, context); assertNotNull(violations); assertFalse(violations.violations(RuleViolation.Type.ERROR).iterator().hasNext()); }