<commit_before>package com.rackspacecloud.blueflood.service;

import static junit.framework.Assert.*;

import org.junit.*;

import java.io.IOException;

public class BluefloodServiceStarterTest {

    @Before
    public void setUp() throws IOException {

        Configuration config = Configuration.getInstance();

        config.init();

        // take from demo/local/config/blueflood.conf
        config.setProperty(CoreConfig.CASSANDRA_HOSTS, "127.0.0.1:9160");
        config.setProperty(CoreConfig.DEFAULT_CASSANDRA_PORT, "9160");
        config.setProperty(CoreConfig.MAX_CASSANDRA_CONNECTIONS, "70");
        config.setProperty(CoreConfig.ROLLUP_KEYSPACE, "DATA");
        config.setProperty(CoreConfig.CLUSTER_NAME, "Test Cluster");
        config.setProperty(CoreConfig.QUERY_MODULES, "com.rackspacecloud.blueflood.service.HttpQueryService");
        config.setProperty(CoreConfig.INGESTION_MODULES, "com.rackspacecloud.blueflood.service.HttpIngestionService");
        config.setProperty(CoreConfig.DISCOVERY_MODULES, "com.rackspacecloud.blueflood.io.ElasticIO");
        config.setProperty(CoreConfig.EVENTS_MODULES, "com.rackspacecloud.blueflood.io.EventElasticSearchIO");
        config.setProperty(CoreConfig.ENUMS_DISCOVERY_MODULES, "com.rackspacecloud.blueflood.io.EnumElasticIO");
        config.setProperty(CoreConfig.MAX_ROLLUP_READ_THREADS, "20");
        config.setProperty(CoreConfig.MAX_ROLLUP_WRITE_THREADS, "20");
        config.setProperty(CoreConfig.MAX_TIMEOUT_WHEN_EXHAUSTED, "2000");
        config.setProperty(CoreConfig.SCHEDULE_POLL_PERIOD, "60000");
        config.setProperty(CoreConfig.CONFIG_REFRESH_PERIOD, "10000");
        config.setProperty(CoreConfig.SHARDS, "ALL");
        config.setProperty(CoreConfig.SHARD_PUSH_PERIOD, "2000");
        config.setProperty(CoreConfig.SHARD_PULL_PERIOD, "20000");
        config.setProperty(CoreConfig.ZOOKEEPER_CLUSTER, "NONE");
        config.setProperty(CoreConfig.SHARD_LOCK_HOLD_PERIOD_MS, "1200000");
        config.setProperty(CoreConfig.SHARD_LOCK_DISINTERESTED_PERIOD_MS, "60000");
        config.setProperty(CoreConfig.SHARD_LOCK_SCAVENGE_INTERVAL_MS, "120000");
        config.setProperty(CoreConfig.MAX_ZK_LOCKS_TO_ACQUIRE_PER_CYCLE, "1");
        config.setProperty(CoreConfig.INTERNAL_API_CLUSTER, "127.0.0.1:50020,127.0.0.1:50020");
        config.setProperty(CoreConfig.GRAPHITE_HOST, "");
        config.setProperty(CoreConfig.GRAPHITE_PORT, "2003");
        config.setProperty(CoreConfig.GRAPHITE_PREFIX, "unconfiguredNode.metrics.");
        config.setProperty(CoreConfig.INGEST_MODE, "false");
        config.setProperty(CoreConfig.ROLLUP_MODE, "false");
        config.setProperty(CoreConfig.QUERY_MODE, "false");
        config.setProperty(CoreConfig.CASSANDRA_MAX_RETRIES, "5");
        config.setProperty("ELASTICSEARCH_HOSTS", "localhost:9300");
        config.setProperty("ELASTICSEARCH_CLUSTERNAME", "elasticsearch");

        BluefloodServiceStarter.SkipInstantiateRestartGauge = true;
    }

    @Test
    public void testStartup() {
        String[] args = new String[0];
        BluefloodServiceStarter.run();

        assertNotNull(args);
    }

    @Test(expected = BluefloodServiceStarterException.class)
    public void testNoCassandraHostsFailsValidation() {

        // given
        Configuration config = Configuration.getInstance();
        config.setProperty(CoreConfig.CASSANDRA_HOSTS, "");

        // when
        BluefloodServiceStarter.validateCassandraHosts();

        // then
        // exception was thrown
    }

    @Test(expected = BluefloodServiceStarterException.class)
    public void testInvalidCassandraHostsFailsValidation() {

        // given
        Configuration config = Configuration.getInstance();<commit_msg>Give the test a better name and more explicit setup.<commit_after>package com.rackspacecloud.blueflood.service;

import static junit.framework.Assert.*;

import org.junit.*;

import java.io.IOException;

public class BluefloodServiceStarterTest {

    @Before
    public void setUp() throws IOException {

        Configuration config = Configuration.getInstance();

        config.init();

        // take from demo/local/config/blueflood.conf
        config.setProperty(CoreConfig.CASSANDRA_HOSTS, "127.0.0.1:9160");
        config.setProperty(CoreConfig.DEFAULT_CASSANDRA_PORT, "9160");
        config.setProperty(CoreConfig.MAX_CASSANDRA_CONNECTIONS, "70");
        config.setProperty(CoreConfig.ROLLUP_KEYSPACE, "DATA");
        config.setProperty(CoreConfig.CLUSTER_NAME, "Test Cluster");
        config.setProperty(CoreConfig.QUERY_MODULES, "com.rackspacecloud.blueflood.service.HttpQueryService");
        config.setProperty(CoreConfig.INGESTION_MODULES, "com.rackspacecloud.blueflood.service.HttpIngestionService");
        config.setProperty(CoreConfig.DISCOVERY_MODULES, "com.rackspacecloud.blueflood.io.ElasticIO");
        config.setProperty(CoreConfig.EVENTS_MODULES, "com.rackspacecloud.blueflood.io.EventElasticSearchIO");
        config.setProperty(CoreConfig.ENUMS_DISCOVERY_MODULES, "com.rackspacecloud.blueflood.io.EnumElasticIO");
        config.setProperty(CoreConfig.MAX_ROLLUP_READ_THREADS, "20");
        config.setProperty(CoreConfig.MAX_ROLLUP_WRITE_THREADS, "20");
        config.setProperty(CoreConfig.MAX_TIMEOUT_WHEN_EXHAUSTED, "2000");
        config.setProperty(CoreConfig.SCHEDULE_POLL_PERIOD, "60000");
        config.setProperty(CoreConfig.CONFIG_REFRESH_PERIOD, "10000");
        config.setProperty(CoreConfig.SHARDS, "ALL");
        config.setProperty(CoreConfig.SHARD_PUSH_PERIOD, "2000");
        config.setProperty(CoreConfig.SHARD_PULL_PERIOD, "20000");
        config.setProperty(CoreConfig.ZOOKEEPER_CLUSTER, "NONE");
        config.setProperty(CoreConfig.SHARD_LOCK_HOLD_PERIOD_MS, "1200000");
        config.setProperty(CoreConfig.SHARD_LOCK_DISINTERESTED_PERIOD_MS, "60000");
        config.setProperty(CoreConfig.SHARD_LOCK_SCAVENGE_INTERVAL_MS, "120000");
        config.setProperty(CoreConfig.MAX_ZK_LOCKS_TO_ACQUIRE_PER_CYCLE, "1");
        config.setProperty(CoreConfig.INTERNAL_API_CLUSTER, "127.0.0.1:50020,127.0.0.1:50020");
        config.setProperty(CoreConfig.GRAPHITE_HOST, "");
        config.setProperty(CoreConfig.GRAPHITE_PORT, "2003");
        config.setProperty(CoreConfig.GRAPHITE_PREFIX, "unconfiguredNode.metrics.");
        config.setProperty(CoreConfig.INGEST_MODE, "false");
        config.setProperty(CoreConfig.ROLLUP_MODE, "false");
        config.setProperty(CoreConfig.QUERY_MODE, "false");
        config.setProperty(CoreConfig.CASSANDRA_MAX_RETRIES, "5");
        config.setProperty("ELASTICSEARCH_HOSTS", "localhost:9300");
        config.setProperty("ELASTICSEARCH_CLUSTERNAME", "elasticsearch");

        BluefloodServiceStarter.SkipInstantiateRestartGauge = true;
    }

    @Test
    public void testAllModesDisabled() {

        // given
        Configuration config = Configuration.getInstance();
        config.setProperty(CoreConfig.INGEST_MODE, "false");
        config.setProperty(CoreConfig.QUERY_MODE, "false");
        config.setProperty(CoreConfig.ROLLUP_MODE, "false");

        // when
        BluefloodServiceStarter.run();

        // then
        // no exception was thrown
    }

    @Test(expected = BluefloodServiceStarterException.class)
    public void testNoCassandraHostsFailsValidation() {

        // given
        Configuration config = Configuration.getInstance();
        config.setProperty(CoreConfig.CASSANDRA_HOSTS, "");

        // when
        BluefloodServiceStarter.validateCassandraHosts();

        // then
        // exception was thrown
    }

    @Test(expected = BluefloodServiceStarterException.class)
    public void testInvalidCassandraHostsFailsValidation() {

        // given
        Configuration config = Configuration.getInstance();
{'fraction_non_alphanumeric': 0.10907928388746803, 'fraction_numerical': 0.02391304347826087, 'mean_word_length': 4.010249839846252, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, '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': '6351347', 'n_tokens_mistral': 2592, 'n_tokens_neox': 2426, 'n_words': 275}