<commit_before>package com.google.cloud.anviltop.hbase;

import org.apache.commons.lang.RandomStringUtils;
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.Test;

import java.io.IOException;

/*
 * Copyright (c) 2013 Google 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.
 */
public class TestAutoFlush extends AbstractTest {
  @Test
  public void testAutoFlushOff() throws Exception {
    HTableInterface tableForWrite = connection.getTable(TABLE_NAME);
    tableForWrite.setAutoFlushTo(false);
    HTableInterface tableForRead = createNewConnection().getTable(TABLE_NAME);
    Get get = quickPutThenGet(tableForWrite);

    Result result = tableForRead.get(get);

    Assert.assertEquals("Expecting no results", 0, result.size());
    tableForWrite.flushCommits();
    result = tableForRead.get(get);
    Assert.assertEquals("Expecting one result", 1, result.size());
  }

  @Test
  public void testAutoFlushOn() throws Exception {
    HTableInterface tableForWrite = connection.getTable(TABLE_NAME);
    tableForWrite.setAutoFlushTo(true);
    HTableInterface tableForRead = createNewConnection().getTable(TABLE_NAME);
    Get get = quickPutThenGet(tableForWrite);

    Result result = tableForRead.get(get);
    Assert.assertEquals("Expecting one result", 1, result.size());
  }

  private Get quickPutThenGet(HTableInterface tableForWrite) throws IOException {
    // Set up the tiny write and read<commit_msg>Check auto-flush default<commit_after>package com.google.cloud.anviltop.hbase;

import org.apache.commons.lang.RandomStringUtils;
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.Test;

import java.io.IOException;

/*
 * Copyright (c) 2013 Google 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.
 */
public class TestAutoFlush extends AbstractTest {
  @Test
  public void testAutoFlushDefault() throws Exception {
    HTableInterface table = connection.getTable(TABLE_NAME);
    Assert.assertTrue("Auto-flush on", table.isAutoFlush());
  }

  @Test
  public void testAutoFlushOff() throws Exception {
    HTableInterface tableForWrite = connection.getTable(TABLE_NAME);
    tableForWrite.setAutoFlushTo(false);
    HTableInterface tableForRead = createNewConnection().getTable(TABLE_NAME);
    Get get = quickPutThenGet(tableForWrite);

    Result result = tableForRead.get(get);

    Assert.assertEquals("Expecting no results", 0, result.size());
    tableForWrite.flushCommits();
    result = tableForRead.get(get);
    Assert.assertEquals("Expecting one result", 1, result.size());
  }

  @Test
  public void testAutoFlushOn() throws Exception {
    HTableInterface tableForWrite = connection.getTable(TABLE_NAME);
    tableForWrite.setAutoFlushTo(true);
    HTableInterface tableForRead = createNewConnection().getTable(TABLE_NAME);
    Get get = quickPutThenGet(tableForWrite);

    Result result = tableForRead.get(get);
    Assert.assertEquals("Expecting one result", 1, result.size());
  }

  private Get quickPutThenGet(HTableInterface tableForWrite) throws IOException {
    // Set up the tiny write and read
{'fraction_non_alphanumeric': 0.09491978609625669, 'fraction_numerical': 0.004901960784313725, 'mean_word_length': 4.696700507614213, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2014517', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1243, 'n_words': 367}