<commit_before>package com.splunk.shep.testutil;

import java.io.File;

import org.apache.commons.lang.math.RandomUtils;
import org.testng.AssertJUnit;

import com.splunk.shep.archiver.model.Bucket;

/**
 * Util for creating a physical and valid bucket on the file system.
 */
public class UtilsBucket {

    /**
     * @return A bucket with random bucket and index names.
     * @see #createTestBucketWithName(String, String)
     */
    public static Bucket createTestBucket() {
	return createTestBucketWithIndexAndName(randomIndexName(),
		randomBucketName());

    }

    private static String randomIndexName() {
	return "index-" + System.currentTimeMillis();
    }

    private static String randomBucketName() {
	long latest = System.currentTimeMillis();
	long earliest = latest - RandomUtils.nextInt(10000);
	return String.format("db_%d_%d_%d", earliest, latest,
		RandomUtils.nextInt(1000));
    }

    /**
     * @return A bucket with specified index and bucket names.
     */
    public static Bucket createTestBucketWithIndexAndName(String index,
	    String bucketName) {
	File bucketDir = createFileFormatedAsBucket(bucketName);
	return createBucketWithIndexInDirectory(index, bucketDir);
    }

    private static Bucket createBucketWithIndexInDirectory(String index,
	    File bucketDir) {
	Bucket testBucket = null;
	try {
	    testBucket = new Bucket(index, bucketDir);
	} catch (Exception e) {
	    UtilsTestNG.failForException("Couldn't create a test bucket", e);
	    throw new RuntimeException(
		    "There was a UtilsTestNG.failForException() method call above me that stoped me from happening. Where did it go?");
	}
	AssertJUnit.assertNotNull(testBucket);

	return testBucket;
    }

    /**
     * @return A directory formated as a bucket.
     */
    public static File createFileFormatedAsBucket(String bucketName) {
	File bucketDir = UtilsFile.createTmpDirectoryWithName(bucketName);
	return formatDirectoryToBeABucket(bucketDir);
    }

    private static File formatDirectoryToBeABucket(File bucketDir) {
	UtilsFile.createDirectoryInParent(bucketDir, "rawdata");
	return bucketDir;
    }

    /**
     * @param parent<commit_msg>When formatting a directory to be a bucket the Bucket utils now also creates a slices.dat file with random data in it just to have a file inside the bucket.<commit_after>package com.splunk.shep.testutil;

import java.io.File;

import org.apache.commons.lang.math.RandomUtils;
import org.testng.AssertJUnit;

import com.splunk.shep.archiver.model.Bucket;

/**
 * Util for creating a physical and valid bucket on the file system.
 */
public class UtilsBucket {

    /**
     * @return A bucket with random bucket and index names.
     * @see #createTestBucketWithName(String, String)
     */
    public static Bucket createTestBucket() {
	return createTestBucketWithIndexAndName(randomIndexName(),
		randomBucketName());

    }

    private static String randomIndexName() {
	return "index-" + System.currentTimeMillis();
    }

    private static String randomBucketName() {
	long latest = System.currentTimeMillis();
	long earliest = latest - RandomUtils.nextInt(10000);
	return String.format("db_%d_%d_%d", earliest, latest,
		RandomUtils.nextInt(1000));
    }

    /**
     * @return A bucket with specified index and bucket names.
     */
    public static Bucket createTestBucketWithIndexAndName(String index,
	    String bucketName) {
	File bucketDir = createFileFormatedAsBucket(bucketName);
	return createBucketWithIndexInDirectory(index, bucketDir);
    }

    private static Bucket createBucketWithIndexInDirectory(String index,
	    File bucketDir) {
	Bucket testBucket = null;
	try {
	    testBucket = new Bucket(index, bucketDir);
	} catch (Exception e) {
	    UtilsTestNG.failForException("Couldn't create a test bucket", e);
	    throw new RuntimeException(
		    "There was a UtilsTestNG.failForException() method call above me that stoped me from happening. Where did it go?");
	}
	AssertJUnit.assertNotNull(testBucket);

	return testBucket;
    }

    /**
     * @return A directory formated as a bucket.
     */
    public static File createFileFormatedAsBucket(String bucketName) {
	File bucketDir = UtilsFile.createTmpDirectoryWithName(bucketName);
	return formatDirectoryToBeABucket(bucketDir);
    }

    private static File formatDirectoryToBeABucket(File bucketDir) {
	File rawdata = UtilsFile
		.createDirectoryInParent(bucketDir, "rawdata");
	File slices = UtilsFile.createFileInParent(rawdata, "slices.dat");
	UtilsFile.populateFileWithRandomContent(slices);
	return bucketDir;
    }

    /**
     * @param parent
{'fraction_non_alphanumeric': 0.09041512714627255, 'fraction_numerical': 0.0039121930015214084, 'mean_word_length': 4.085082872928177, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3013327', 'n_tokens_mistral': 1366, 'n_tokens_neox': 1312, 'n_words': 364}