/*
 * Licensed to Elasticsearch under one or more contributor
 * license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright
 * ownership. Elasticsearch licenses this file to you under
 * the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.elasticsearch.hadoop.qa.kerberos;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

@RunWith(Parameterized.class)
public class AbstractClusterVerificationTests {

    @Parameters
    public static Collection<Object[]> params() {
        List<Object[]> params = new ArrayList<>();
        params.add(new Object[]{"mr",        "part-m-00000", 345, true});
        params.add(new Object[]{"spark",     "part-00000",   345, true});
        params.add(new Object[]{"hive",      "000000_0",     345, false});
        params.add(new Object[]{"pig",       "part-m-00000", 345, true});
        return params;
    }

    private String integrationName;
    private String dataFileName;
    private int expectedLineCount;
    private boolean hasSuccessMarker;

    public AbstractClusterVerificationTests(String integrationName, String dataFileName, int expectedLineCount, boolean hasSuccessMarker) {
        this.integrationName = integrationName;
        this.dataFileName = dataFileName;
        this.expectedLineCount = expectedLineCount;
        this.hasSuccessMarker = hasSuccessMarker;
    }

    @Test
    public void testOutputContents() throws Exception {
        File dataDirectory = new File("build/data");
        File integrationDataDir = new File(dataDirectory, integrationName);

        if (hasSuccessMarker) {
            File successMarker = new File(integrationDataDir, "_SUCCESS");
            Assert.assertTrue("Success marker expected for integration [" + integrationName + "] but could not find it.",
                    successMarker.exists());
        }

        File dataFile = new File(integrationDataDir, dataFileName);
        Assert.assertTrue("Expected data file [" + dataFile + "] to exist but could not find it.", dataFile.exists());
        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(dataFile)));
        int lines = 0;
        while (reader.readLine() != null) {
            lines++;
        }
        reader.close();
        Assert.assertEquals(expectedLineCount, lines);
    }
}

@@ -1443,37 +1443,32 @@
         %22part-m-
-00000
 %22, 345, true%7D);%0A
@@ -1518,21 +1518,16 @@
   %22part-
-00000
 %22,   345
@@ -1664,21 +1664,16 @@
 %22part-m-
-00000
 %22, 345, 
@@ -1769,28 +1769,30 @@
 ing dataFile
-Name
+Prefix
 ;%0A    privat
@@ -1938,20 +1938,22 @@
 dataFile
-Name
+Prefix
 , int ex
@@ -2066,20 +2066,22 @@
 dataFile
-Name
+Prefix
  = dataF
@@ -2083,20 +2083,22 @@
 dataFile
-Name
+Prefix
 ;%0A      
@@ -2693,33 +2693,57 @@
     
-File dataFile = new 
+int lines = 0;%0A        for (File directory
 File
-(
+ : 
 inte
@@ -2760,144 +2760,102 @@
 aDir
-, dataFileName);%0A        Assert.assertTrue(%22Expected data file %5B%22 + dataFile + %22%5D to exist but could not find it.%22, dataFile.exists());%0A
+.listFiles()) %7B%0A            if (directoryFile.getName().startsWith(dataFilePrefix)) %7B%0A        
     
@@ -2944,19 +2944,24 @@
 Stream(d
-ata
+irectory
 File)));
@@ -2965,39 +2965,24 @@
 ));%0A        
-int lines = 0;%0A
         whil
@@ -3025,16 +3025,24 @@
         
+        
 lines++;
@@ -3042,16 +3042,24 @@
 ines++;%0A
+        
         
@@ -3060,16 +3060,24 @@
       %7D%0A
+        
         
@@ -3088,24 +3088,48 @@
 er.close();%0A
+            %7D%0A        %7D%0A
         Asse

Update test to account for multiple output files (#1246)