2 * ===============================LICENSE_START======================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============================LICENSE_END===========================================
21 package org.onap.dcae.apod.analytics.cdap.plugins.batch.sink.dmaap;
23 import org.apache.hadoop.io.NullWritable;
24 import org.apache.hadoop.mapreduce.JobContext;
25 import org.apache.hadoop.mapreduce.OutputCommitter;
26 import org.apache.hadoop.mapreduce.RecordWriter;
27 import org.apache.hadoop.mapreduce.TaskAttemptContext;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.mockito.Mockito;
31 import org.onap.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest;
33 import static org.junit.Assert.assertFalse;
34 import static org.junit.Assert.assertNotNull;
35 import static org.junit.Assert.assertTrue;
36 import static org.mockito.Mockito.when;
39 * @author Rajiv Singla . Creation Date: 1/30/2017.
41 public class DMaaPMROutputFormatTest extends BaseAnalyticsCDAPPluginsUnitTest {
43 private DMaaPMROutputFormat dMaaPMROutputFormat;
46 public void before() {
47 dMaaPMROutputFormat = new DMaaPMROutputFormat();
51 public void testGetRecordWriter() throws Exception {
52 final TaskAttemptContext taskAttemptContext = Mockito.mock(TaskAttemptContext.class);
53 when(taskAttemptContext.getConfiguration()).thenReturn(getTestConfiguration());
54 final RecordWriter<String, NullWritable> recordWriter = dMaaPMROutputFormat.getRecordWriter(taskAttemptContext);
55 assertNotNull(recordWriter);
56 final JobContext jobContext = Mockito.mock(JobContext.class);
57 dMaaPMROutputFormat.checkOutputSpecs(jobContext);
61 public void testGetOutputCommitter() throws Exception {
62 final TaskAttemptContext taskAttemptContext = Mockito.mock(TaskAttemptContext.class);
63 final OutputCommitter outputCommitter = dMaaPMROutputFormat.getOutputCommitter(taskAttemptContext);
64 assertTrue(outputCommitter.getClass().equals(DMaaPMROutputFormat.NoOpOutputCommitter.class));
65 final JobContext jobContext = Mockito.mock(JobContext.class);
66 outputCommitter.setupJob(jobContext);
67 outputCommitter.setupTask(taskAttemptContext);
68 assertFalse(outputCommitter.needsTaskCommit(taskAttemptContext));
69 outputCommitter.commitJob(jobContext);
70 outputCommitter.commitTask(taskAttemptContext);
71 outputCommitter.abortTask(taskAttemptContext);