/**
 * Copyright 2016 Palantir Technologies
 *
 * Licensed under the BSD-3 License (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://opensource.org/licenses/BSD-3-Clause
 *
 * 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.palantir.atlasdb.table.description;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.equalTo;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import com.palantir.atlasdb.keyvalue.api.Namespace;

public class SchemaHotspottingTest {
    @Rule
    public TemporaryFolder temporaryFolder = new TemporaryFolder();

    Schema hotspottingSchema = getHotspottingSchema();

    private static Schema getHotspottingSchema() {
        Schema suffersFromHotspoting = new Schema("SuffersFromHotspoting", "unused", Namespace.DEFAULT_NAMESPACE);
        suffersFromHotspoting.addTableDefinition("HotspottingTable", new TableDefinition() {{
            rowName();
                rowComponent("Hotspotter", ValueType.VAR_STRING);
            noColumns();
        }});
        return suffersFromHotspoting;
    }

    private static Schema getIgnoredHotspottingSchema() {
        Schema ignoredHotspotting = new Schema("IgnoredHotspotting", "valid.package", Namespace.DEFAULT_NAMESPACE);
        ignoredHotspotting.addTableDefinition("IgnoredHotspottingTable", new TableDefinition() {{
            ignoreHotspottingChecks();
            rowName();
                rowComponent("Hotspotter", ValueType.VAR_STRING);
            noColumns();
        }});
        return ignoredHotspotting;
    }

    @Test (expected = IllegalStateException.class)
    public void testHardFailOnValidateOfHotspottingSchema() {
        hotspottingSchema.validate();
    }

    @Test (expected = IllegalStateException.class)
    public void testFailToGenerateHotspottingSchema() throws IOException {
        hotspottingSchema.renderTables(new TemporaryFolder().getRoot());
    }

    @Test
    public void testNoFailureWhenHotspottingIgnored() {
        getIgnoredHotspottingSchema().validate();
    }

    @Test
    public void testSuccessfulGenerationWhenHotspottingIgnored() throws IOException {
        File srcDir = temporaryFolder.getRoot();
        getIgnoredHotspottingSchema().renderTables(srcDir);

        assertThat(Arrays.asList(srcDir.list()), contains(equalTo("valid")));

        File validDirectory = srcDir.listFiles()[0];
        assertThat(Arrays.asList(validDirectory.list()), contains(equalTo("package")));
        assertThat(Arrays.asList(validDirectory.listFiles()[0].list()), containsInAnyOrder(equalTo("IgnoredHotspottingTableFactory.java"), equalTo("IgnoredHotspottingTableTable.java")));
    }
}
@@ -1647,24 +1647,561 @@
 ing;%0A    %7D%0A%0A
+    private static Schema getFirstRowComponentHashedSchema() %7B%0A        Schema firstRowComponentHashedToAvoidHotspotting = new Schema(%22SuffersFromHotspoting%22, %22unused%22, Namespace.DEFAULT_NAMESPACE);%0A        firstRowComponentHashedToAvoidHotspotting.addTableDefinition(%22HotspottingTable%22, new TableDefinition() %7B%7B%0A            rowName();%0A            hashFirstRowComponent();%0A            rowComponent(%22Hotspotter%22, ValueType.VAR_STRING);%0A            noColumns();%0A        %7D%7D);%0A        return firstRowComponentHashedToAvoidHotspotting;%0A    %7D%0A%0A
     private 
@@ -3147,32 +3147,165 @@
 idate();%0A    %7D%0A%0A
+    @Test%0A    public void testNoFailureWhenFirstRowComponentHashed() %7B%0A        getFirstRowComponentHashedSchema().validate();%0A    %7D%0A%0A
     @Test%0A    pu

Add test to ensure hotSpotting error is not hit with hasFirstRowCompnent