/**
 * Copyright 2015 Netflix, Inc.
 *
 * Licensed 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 com.netflix.spectator.spark;

import com.netflix.spectator.api.DefaultId;
import com.netflix.spectator.api.Id;
import com.typesafe.config.ConfigFactory;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class SparkNameFunctionTest {

  private final SparkNameFunction f = SparkNameFunction.fromConfig(ConfigFactory.load());

  @Test
  public void executorName() {
    final String name = "app-20150309231421-0000.0.executor.filesystem.file.largeRead_ops";
    final Id expected = new DefaultId("spark.filesystem.file.largeRead_ops")
        .withTag("role", "executor")
        .withTag("appId", "app-20150309231421-0000")
        .withTag("executorId", "0");
    Assert.assertEquals(expected, f.apply(name));
  }

  @Test
  public void driverName() {
    final String name = "app-20150309231421-0000.driver.BlockManager.disk.diskSpaceUsed_MB";
    final Id expected = new DefaultId("spark.BlockManager.disk.diskSpaceUsed")
        .withTag("role", "driver")
        .withTag("appId", "app-20150309231421-0000");
    Assert.assertEquals(expected, f.apply(name));
  }

  @Test
  public void driverName2() {
    final String name = "app-20150309231421-0000.driver.DAGScheduler.job.activeJobs";
    final Id expected = new DefaultId("spark.DAGScheduler.job.activeJobs")
        .withTag("role", "driver")
        .withTag("appId", "app-20150309231421-0000");
    Assert.assertEquals(expected, f.apply(name));
  }

  @Test
  public void driverName3() {
    final String name = "local-1429219722964.<driver>.DAGScheduler.job.activeJobs";
    final Id expected = new DefaultId("spark.DAGScheduler.job.activeJobs")
        .withTag("role", "driver")
        .withTag("appId", "local-1429219722964");
    Assert.assertEquals(expected, f.apply(name));
  }

  @Test
  public void applicationName() {
    final String name = "application.Spark shell.1425968061869.cores";
    final Id expected = new DefaultId("spark.cores")
        .withTag("role", "application")
        .withTag("appName", "Spark shell");
    Assert.assertEquals(expected, f.apply(name));
  }

  @Test
  public void applicationName2() {
    final String name = "application.SubscriptionEnded.1429226958083.runtime_ms";
    final Id expected = new DefaultId("spark.runtime")
        .withTag("role", "application")
        .withTag("appName", "SubscriptionEnded");
    Assert.assertEquals(expected, f.apply(name));
  }

  @Test
  public void masterName() {
    final String name = "master.apps";
    final Id expected = new DefaultId("spark.apps")
        .withTag("role", "master");
    Assert.assertEquals(expected, f.apply(name));
  }

  @Test
  public void workerName() {
    final String name = "worker.memFree_MB";
    final Id expected = new DefaultId("spark.memFree")
        .withTag("role", "worker");
    Assert.assertEquals(expected, f.apply(name));
  }

}

@@ -1019,24 +1019,178 @@
 ad());%0A%0A
+  private void assertEquals(Id expected, Id actual) %7B%0A    Assert.assertEquals(((DefaultId) expected).normalize(), ((DefaultId) actual).normalize());%0A  %7D%0A%0A
   @Test%0A
   public
@@ -1173,32 +1173,32 @@
 );%0A  %7D%0A%0A  @Test%0A
-
   public void ex
@@ -1504,39 +1504,32 @@
 rId%22, %220%22);%0A    
-Assert.
 assertEquals(exp
@@ -1850,39 +1850,32 @@
 421-0000%22);%0A    
-Assert.
 assertEquals(exp
@@ -2186,39 +2186,32 @@
 421-0000%22);%0A    
-Assert.
 assertEquals(exp
@@ -2516,39 +2516,32 @@
 19722964%22);%0A    
-Assert.
 assertEquals(exp
@@ -2814,39 +2814,32 @@
 rk shell%22);%0A    
-Assert.
 assertEquals(exp
@@ -3132,39 +3132,32 @@
 ionEnded%22);%0A    
-Assert.
 assertEquals(exp
@@ -3344,39 +3344,32 @@
  %22master%22);%0A    
-Assert.
 assertEquals(exp
@@ -3569,27 +3569,20 @@
 rker%22);%0A
+
     
-Assert.
 assertEq

fix test cases on jdk7