/**
 * Copyright 2011-2016 Asakusa Framework Team.
 *
 * 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.asakusafw.testdriver.testing.moderator;

import java.io.IOException;
import java.util.Objects;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.asakusafw.runtime.io.ModelOutput;
import com.asakusafw.runtime.stage.temporary.TemporaryStorage;
import com.asakusafw.testdriver.core.BaseExporterRetriever;
import com.asakusafw.testdriver.core.DataModelDefinition;
import com.asakusafw.testdriver.core.DataModelSource;
import com.asakusafw.testdriver.core.ExporterRetriever;
import com.asakusafw.testdriver.core.TestContext;
import com.asakusafw.testdriver.hadoop.ConfigurationFactory;

/**
 * Implementation of {@link ExporterRetriever} for {@link MockExporterDescription}s.
 * @since 0.9.0
 */
public class MockExporterRetriever extends BaseExporterRetriever<MockExporterDescription> {

    static final Logger LOG = LoggerFactory.getLogger(MockExporterRetriever.class);

    private final ConfigurationFactory configurations;

    /**
     * Creates a new instance with default configurations.
     */
    public MockExporterRetriever() {
        this(ConfigurationFactory.getDefault());
    }

    /**
     * Creates a new instance.
     * @param configurations the configuration factory
     * @throws IllegalArgumentException if some parameters were {@code null}
     */
    public MockExporterRetriever(ConfigurationFactory configurations) {
        this.configurations = Objects.requireNonNull(configurations, "configurations must not be null"); //$NON-NLS-1$
    }

    @Override
    public void truncate(
            MockExporterDescription description,
            TestContext context) throws IOException {
        LOG.debug("deleting output directory: {}", description); //$NON-NLS-1$
        Configuration config = configurations.newInstance();
        FileSystem fs = FileSystem.get(config);
        Path path = new Path(description.getGlob());
        fs.delete(path, false);
    }

    @Override
    public <V> ModelOutput<V> createOutput(
            DataModelDefinition<V> definition,
            MockExporterDescription description,
            TestContext context) throws IOException {
        Configuration conf = configurations.newInstance();
        ModelOutput<V> output = TemporaryStorage.openOutput(
                conf,
                definition.getModelClass(),
                new Path(description.getGlob().replace('*', '_')));
        return output;
    }

    @Override
    public <V> DataModelSource createSource(
            DataModelDefinition<V> definition,
            MockExporterDescription description,
            TestContext context) throws IOException {
        Configuration conf = configurations.newInstance();
        return new TemporaryDataModelSource(conf, definition, description.getGlob());
    }
}

@@ -755,24 +755,64 @@
 figuration;%0A
+import org.apache.hadoop.fs.FileStatus;%0A
 import org.a
@@ -2647,24 +2647,141 @@
 getGlob());%0A
+        try %7B%0A            FileStatus%5B%5D stats = fs.globStatus(path);%0A            for (FileStatus s : stats) %7B%0A        
         fs.d
@@ -2786,20 +2786,27 @@
 .delete(
-p
+s.getP
 ath
+()
 , false)
@@ -2807,16 +2807,125 @@
 false);%0A
+            %7D%0A        %7D catch (IOException e) %7B%0A            LOG.debug(%22exception in truncate%22, e);%0A        %7D%0A
     %7D%0A%0A 

Fix tests in asakusa-test-driver.