<commit_before>package com.softartisans.timberwolf.integrated;

import com.softartisans.timberwolf.hbase.HBaseConfigurator;
import com.softartisans.timberwolf.hbase.HBaseManager;
import com.softartisans.timberwolf.hbase.IHBaseTable;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class TestHBaseIntegration
{
    private static HBaseManager hBaseManager;
    private static final String tableName = "testTable";
    private static final String ZOO_KEEPER_QUORUM_PROPERTY_NAME = "ZooKeeperQuorum";
    private static final String ZOO_KEEPER_CLIENT_PORT_PROPERTY_NAME = "ZooKeeperClientPort";

    @Rule
    public IntegrationTestProperties properties = new IntegrationTestProperties(ZOO_KEEPER_QUORUM_PROPERTY_NAME,
                                                                                ZOO_KEEPER_CLIENT_PORT_PROPERTY_NAME);

    private static final String defaultColumnFamily = "h";

    private static void createTable(String tableName)
    {
        List<String> cfs = new ArrayList<String>();
        cfs.add(defaultColumnFamily);
        hBaseManager.createTable(tableName,cfs);
        Assert.assertTrue(hBaseManager.tableExists(tableName));
    }

    private static void deleteTable(String tableName)
    {
        hBaseManager.deleteTable(tableName);
        Assert.assertFalse(hBaseManager.tableExists(tableName));
    }

    private static IHBaseTable getTable(String tableName)
    {
        IHBaseTable table = hBaseManager.getTable(tableName);
        Assert.assertEquals(tableName, table.getName());
        return table;
    }

    private static Put createPut(String rowKey, String family, String qualifier,
                                 String value)
    {
        Put put = new Put(Bytes.toBytes(rowKey));
        put.add(Bytes.toBytes(family),
                Bytes.toBytes(qualifier),
                Bytes.toBytes(value));
        return put;
    }

    private static Get createGet(String rowKey, String family)
    {
        Get get = new Get(Bytes.toBytes(rowKey));
        get.addFamily(Bytes.toBytes(family));
        return get;
    }

    /**
     * Fixture setup.
     */
    @BeforeClass
    public static void classSetUp()
    {
        String zooKeeperQuorum = IntegrationTestProperties.getProperty(ZOO_KEEPER_QUORUM_PROPERTY_NAME);
        String zooKeeperClientPort = IntegrationTestProperties.getProperty(ZOO_KEEPER_CLIENT_PORT_PROPERTY_NAME);
        if (zooKeeperQuorum != null && zooKeeperClientPort != null)
        {
            hBaseManager = new HBaseManager(zooKeeperQuorum, zooKeeperClientPort);
        }
    }

    /**
     * Fixture tear down.
     */
    @AfterClass
    public static void tearDown()
    {
        if (hBaseManager != null)
        {
            hBaseManager.close();
        }
    }

    /**
     * Tests that we can create and delete a table on the remote HBase instance.
     */
    @Test
    public void testRemoteCreateDeleteTable()
    {
        String tableName = "HBaseIntegratedtestRemoteConnection";

        createTable(tableName);
        deleteTable(tableName);
    }

    /**
     * Tests getting a remote table instance.
     */
    @Test
    public void testRemoteGetTable()
    {
        String tableName = "HBaseIntegratedtestRemoteGetTable";

        createTable(tableName);
        IHBaseTable table = getTable(tableName);
        table.close();

        deleteTable(tableName);
    }

    /**
     *  Tests a remote put operation and compares the values from an HBase
     *  get operation.
     */
    @Test
    public void testRemotePut()
    {
        String tableName = "HBaseIntegratedtestRemotePut";
        String rowKey = "aGenericRowKey";
        String qualifier = "aGenericQualifier";
        String value = "someValue";

        createTable(tableName);
        IHBaseTable table = getTable(tableName);

        Put put = createPut(rowKey,defaultColumnFamily,
                qualifier,value);
        table.put(put);
        table.close();

        // We want to do the read without using the manager.
        Configuration configuration =
                HBaseConfigurator.createConfiguration(
                        IntegrationTestProperties.getProperty(ZOO_KEEPER_QUORUM_PROPERTY_NAME),
                        IntegrationTestProperties.getProperty(ZOO_KEEPER_CLIENT_PORT_PROPERTY_NAME));
        try
        {
            HTableInterface tableInterface = new HTable(configuration,
                    tableName);

            Result result = tableInterface.get(createGet(rowKey,
                    defaultColumnFamily));
            String tableValue = Bytes.toString(result.getValue(
                    Bytes.toBytes(defaultColumnFamily),
                    Bytes.toBytes(qualifier)));
            Assert.assertEquals(value,tableValue);
        }
        catch (IOException e)
        {
            Assert.fail("Exception getting our record: " + e.getMessage());
        }
        finally
        {
            deleteTable(tableName);
        }
    }

}<commit_msg>Switched TestHBaseIntegration to the htable rule<commit_after>package com.softartisans.timberwolf.integrated;

import com.softartisans.timberwolf.hbase.IHBaseTable;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

import java.io.IOException;

public class TestHBaseIntegration
{
    @Rule
    public HTableResource htable = new HTableResource();

    private static Put createPut(String rowKey, String family, String qualifier,
                                 String value)
    {
        Put put = new Put(Bytes.toBytes(rowKey));
        put.add(Bytes.toBytes(family),
                Bytes.toBytes(qualifier),
                Bytes.toBytes(value));
        return put;
    }

    private static Get createGet(String rowKey, String family)
    {
        Get get = new Get(Bytes.toBytes(rowKey));
        get.addFamily(Bytes.toBytes(family));
        return get;
    }

    /**
     * Tests that we can create and delete a table on the remote HBase instance.
     */
    @Test
    public void testRemoteCreateTable()
    {
        Assert.assertTrue(htable.exists());
    }

    /**
     * Tests getting a remote table instance.
     */
    @Test
    public void testRemoteGetTable() throws IOException
    {
        String tableName = htable.getName();
        IHBaseTable table = htable.regetTable();
        Assert.assertEquals(tableName, table.getName());
    }

    /**
     *  Tests a remote put operation and compares the values from an HBase
     *  get operation.
     */
    @Test
    public void testRemotePut()
    {
        String rowKey = "aGenericRowKey";
        String qualifier = "aGenericQualifier";
        String value = "someValue";

        IHBaseTable table = htable.getTable();

        Put put = createPut(rowKey, htable.getFamily(), qualifier,value);
        table.put(put);

        try
        {
            // We want to do the read without using the manager.
            HTableInterface tableInterface = htable.getTestingTable();

            Result result = tableInterface.get(createGet(rowKey,htable.getFamily()));
            String tableValue = Bytes.toString(result.getValue(Bytes.toBytes(htable.getFamily()),
                                                               Bytes.toBytes(qualifier)));
            Assert.assertEquals(value,tableValue);
        }
        catch (IOException e)
        {
            Assert.fail("Exception getting our record: " + e.getMessage());
        }
    }

}
{'fraction_non_alphanumeric': 0.08727091385114076, 'fraction_numerical': 0.0, 'mean_word_length': 2.391966173361522, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1222363', 'n_tokens_mistral': 2226, 'n_tokens_neox': 2160, 'n_words': 467}