@Test public void testOpenWithConfigurableReader() throws Exception { ConfigurableDummyRecordReader recordReader = mock(ConfigurableDummyRecordReader.class); DummyInputFormat inputFormat = mock(DummyInputFormat.class); when(inputFormat.getRecordReader(any(InputSplit.class), any(JobConf.class), any(Reporter.class))).thenReturn(recordReader); HadoopInputFormat<String, Long> hadoopInputFormat = new HadoopInputFormat<>(inputFormat, String.class, Long.class, new JobConf()); hadoopInputFormat.open(getHadoopInputSplit()); verify(inputFormat, times(1)).getRecordReader(any(InputSplit.class), any(JobConf.class), any(Reporter.class)); verify(recordReader, times(1)).setConf(any(JobConf.class)); verify(recordReader, times(1)).createKey(); verify(recordReader, times(1)).createValue(); assertThat(hadoopInputFormat.fetched, is(false)); }
/** * A shortcut to the frequently used <code>is(instanceOf(SomeClass.class))</code>. * <p/> * For example: * <pre>assertThat(cheese, isA(Cheddar.class))</pre> * instead of: * <pre>assertThat(cheese, is(instanceOf(Cheddar.class)))</pre> */ public static <T> org.hamcrest.Matcher<T> isA(java.lang.Class<T> type) { return org.hamcrest.core.Is.<T>isA(type); }
/** * Decorates another Matcher, retaining its behaviour, but allowing tests * to be slightly more expressive. * For example: * <pre>assertThat(cheese, is(equalTo(smelly)))</pre> * instead of: * <pre>assertThat(cheese, equalTo(smelly))</pre> * */ public static <T> Matcher<T> is(Matcher<T> matcher) { return new Is<>(matcher); }
@Test public void shouldDelegateGetSegmentToParentIfIndexNotEqualToSizeMinusOne() { Path.Segment segment = mock(Path.Segment.class); parent = mock(Path.class); when(parent.size()).thenReturn(10); path = new ChildPath(parent, segment("d")); when(parent.getSegment(anyInt())).thenReturn(segment); for (int i = 0; i < path.size() - 1; ++i) { assertThat(path.getSegment(i), is(sameInstance(segment))); } verify(parent, times(parent.size())).getSegment(anyInt()); }
@Test public void testReplace2Args_doesNotReplace() throws Exception { when(numberAuthoritativeTier.replace(eq(1), eq("one"))).thenReturn(null); TieredStore<Number, CharSequence> tieredStore = new TieredStore<>(numberCachingTier, numberAuthoritativeTier); assertThat(tieredStore.replace(1, "one"), is(nullValue())); verify(numberCachingTier).invalidate(any(Number.class)); verify(numberAuthoritativeTier, times(1)).replace(eq(1), eq("one")); }
@Test public void testFetchNextRecordReaderHasNewValue() throws Exception { DummyRecordReader recordReader = mock(DummyRecordReader.class); when(recordReader.nextKeyValue()).thenReturn(true); HadoopInputFormat<String, Long> hadoopInputFormat = setupHadoopInputFormat(new DummyInputFormat(), Job.getInstance(), recordReader); hadoopInputFormat.fetchNext(); assertThat(hadoopInputFormat.fetched, is(true)); assertThat(hadoopInputFormat.hasNext, is(true)); }
@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))); }
@Test void shouldNotifyListenerOnRotationErrorDuringJobExecution() throws Exception { RotationListener rotationListener = mock( RotationListener.class ); Executor executor = mock( Executor.class ); RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier( fileSystem, logFile, 10, 0, 10, executor, rotationListener ); OutputStream outputStream = supplier.get(); RejectedExecutionException exception = new RejectedExecutionException( "text exception" ); doThrow( exception ).when( executor ).execute( any( Runnable.class ) ); write( supplier, "A string longer than 10 bytes" ); assertThat( supplier.get(), is( outputStream ) ); verify( rotationListener ).rotationError( exception, outputStream ); }
@Test public void testFetchNextRecordReaderThrowsException() throws Exception { DummyRecordReader recordReader = mock(DummyRecordReader.class); when(recordReader.nextKeyValue()).thenThrow(new InterruptedException()); HadoopInputFormat<String, Long> hadoopInputFormat = setupHadoopInputFormat(new DummyInputFormat(), Job.getInstance(), recordReader); exception.expect(IOException.class); hadoopInputFormat.fetchNext(); assertThat(hadoopInputFormat.hasNext, is(true)); }
@Test public void should_extract_http_method() { when(request.getMethod()).thenReturn(HttpMethod.GET); assertThat(extractor.extract(request).get(), is(HttpMethod.GET.name())); } }
@Test public void setsExpressionPayload() throws MuleException { setPayloadMessageProcessor.setValue(EXPRESSION); when(expressionManager.isExpression(EXPRESSION)).thenReturn(true); setPayloadMessageProcessor.initialise(); TypedValue typedValue = new TypedValue(PLAIN_TEXT, DataType.STRING); when(expressionManager.evaluate(EXPRESSION, testEvent())).thenReturn(typedValue); when(expressionManager.evaluate(eq(EXPRESSION), eq(testEvent()), any(CoreEvent.Builder.class), eq(null))) .thenReturn(typedValue); CoreEvent response = setPayloadMessageProcessor.process(testEvent()); assertThat(response.getMessage().getPayload().getValue(), is(PLAIN_TEXT)); }
@Test public void testPutIfAbsent_whenAbsent() throws Exception { TieredStore<Number, CharSequence> tieredStore = new TieredStore<>(numberCachingTier, numberAuthoritativeTier); assertThat(tieredStore.putIfAbsent(1, "one", b -> {}), is(nullValue())); verify(numberCachingTier, times(1)).invalidate(eq(1)); verify(numberAuthoritativeTier, times(1)).putIfAbsent(eq(1), eq("one"), any()); }
@Test public void checksWhetherHeadersExist() { assertThat(headers.contains("header1"), is(true)); assertThat(headers.contains("header2"), is(true)); assertThat(headers.contains("nonExistent"), is(false)); }
assumeThat(dockerClient.version(), is(execCompatibleDockerVersion())); verify(registrar, never()).register(any(ServiceRegistration.class)); dockerClient.close(); verify(registrar, timeout((int) SECONDS.toMillis(LONG_WAIT_SECONDS))) .register(registrationCaptor.capture()); final ServiceRegistration serviceRegistration = registrationCaptor.getValue();
@Test public void transformerFactoryProperties() { SetPropertyAnswer setPropertyAnswer = new SetPropertyAnswer(transformerFactory); doAnswer(setPropertyAnswer).when(transformerFactoryWrapper).setAttribute(anyString(), anyObject()); defaultXMLSecureFactories.configureTransformerFactory(transformerFactoryWrapper); assertThat(setPropertyAnswer.exception, is(nullValue())); for (String property : FACTORY_ATTRIBUTES) { verify(transformerFactoryWrapper).setAttribute(property, ""); } }
@Test public void emptyHeadersHasEmptyNames() { HttpHeaders httpHeaders = new HttpHeaders.Builder().build(); assertThat(httpHeaders.names(), is(emptyIterable())); }
@Test public void resolveBooleanWithBooleanStringValue() { AttributeEvaluator attributeEvaluator = new AttributeEvaluator("#[mel:expression]", BOOLEAN); attributeEvaluator.initialize(mockExpressionManager); final String expectedValue = "true"; doReturn(new TypedValue<>(Boolean.valueOf(expectedValue), BOOLEAN)) .when(mockExpressionManager) .evaluate(anyString(), any(DataType.class), any(BindingContext.class), any(CoreEvent.class)); assertThat(attributeEvaluator.resolveValue(event), is(Boolean.valueOf(expectedValue))); }
private void assertLogOccurred( Level level, String message ) { ArrayList<LoggingEvent> events = getLoggingEvents(); assertThat( events, hasSize( 1 ) ); LoggingEvent event = events.get( 0 ); assertThat( event.getLoggerName(), is( getClass().getName() ) ); assertThat( event.getLevel(), is( level ) ); assertThat( event.getMessage(), is( message ) ); }
@Test public void retrievesPreviouslyRegisteredTimer() { Timer timer = metricRegistry.timer("newTimer"); assertThat(timer, is(notNullValue())); assertThat(metricRegistry.timer("newTimer"), is(sameInstance(timer))); }
@Test void shouldCreatePathThatPointsToFile() throws Exception { fsa.mkdirs( path ); assertTrue( fsa.fileExists( path ) ); path = new File( path, "some_file" ); try ( StoreChannel channel = fsa.create( path ) ) { assertThat( channel, is( not( nullValue() ) ) ); fsa.mkdirs( path ); assertTrue( fsa.fileExists( path ) ); } }