/*
 * Licensed to the University of California, Berkeley under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for additional information regarding
 * copyright ownership. The ASF 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 tachyon.hadoop.contract;

import java.io.IOException;
import java.net.URI;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.contract.AbstractFSContract;

import tachyon.Constants;
import tachyon.exception.ConnectionFailedException;
import tachyon.hadoop.TFS;
import tachyon.master.LocalTachyonCluster;

/**
 * This class provides an implementation of {@link AbstractFSContract} using
 * {@link tachyon.hadoop.TFS}. This will be used to run Hadoop Contract tests which verify the
 * {@link tachyon.hadoop.AbstractTFS} interface.
 * More information can be found here:
 * http://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/filesystem/testing.html
 */
public class TachyonFSContract extends AbstractFSContract {

  public static final String CONTRACT_XML = "contract/tachyonfs.xml";
  public static final String SYSPROP_TEST_BUILD_DATA = "test.build.data";
  public static final String DEFAULT_TEST_BUILD_DATA_DIR = "test/build/data";
  private FileSystem mFS;

  public TachyonFSContract(Configuration conf) {
    super(conf);
    //insert the base features
    addConfResource(getContractXml());
  }

  /**
   * Return the contract file for this filesystem
   * @return the XML
   */
  protected String getContractXml() {
    return CONTRACT_XML;
  }

  @Override
  public void init() throws IOException {
    super.init();
    Configuration conf = new Configuration();
    conf.set("fs.tachyon.impl", TFS.class.getName());

    // Start local Tachyon cluster
    LocalTachyonCluster localcluster = new LocalTachyonCluster(100000000, 100000, 1024);
    try {
      localcluster.start();
    } catch (ConnectionFailedException e) {
      throw new IOException(e);
    }
    URI uri = URI.create(localcluster.getMasterUri());

    mFS = FileSystem.get(uri, conf);
  }

  @Override
  public FileSystem getTestFileSystem() throws IOException {
    return mFS;
  }

  @Override
  public String getScheme() {
    return Constants.SCHEME;
  }

  @Override
  public Path getTestPath() {
    Path path = mFS.makeQualified(new Path(getTestDataDir()));
    return path;
  }

  /**
   * Get the test data directory
   * @return the directory for test data
   */
  protected String getTestDataDir() {
    return System.getProperty(SYSPROP_TEST_BUILD_DATA, DEFAULT_TEST_BUILD_DATA_DIR);
  }
}

@@ -1077,60 +1077,8 @@
 ts;%0A
-import tachyon.exception.ConnectionFailedException;%0A
 impo
@@ -1794,16 +1794,68 @@
 /data%22;%0A
+  private LocalTachyonCluster mLocalTachyonCluster;%0A
   privat
@@ -1922,27 +1922,92 @@
 conf
-) %7B%0A    super(conf)
+, LocalTachyonCluster cluster) %7B%0A    super(conf);%0A    mLocalTachyonCluster = cluster
 ;%0A  
@@ -2407,252 +2407,8 @@
 );%0A%0A
-    // Start local Tachyon cluster%0A    LocalTachyonCluster localcluster = new LocalTachyonCluster(100000000, 100000, 1024);%0A    try %7B%0A      localcluster.start();%0A    %7D catch (ConnectionFailedException e) %7B%0A      throw new IOException(e);%0A    %7D%0A
     
@@ -2432,14 +2432,22 @@
 ate(
-l
+mL
 ocal
-c
+TachyonC
 lust

Remove cluster creation from TachyonFSContract