Search in sources :

Example 1 with InMemoryInstance

use of datawave.accumulo.inmemory.InMemoryInstance in project datawave by NationalSecurityAgency.

the class NumShardsTest method testUpdateCacheWithoutEntries.

@Test
public void testUpdateCacheWithoutEntries() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, IOException, ParseException {
    // configure mock accumulo instance and populate with a couple of multiple numshards entries
    PasswordToken noPasswordToken = new PasswordToken();
    InMemoryInstance i = new InMemoryInstance("mock2");
    Connector connector = i.getConnector("root", noPasswordToken);
    Configuration conf = new Configuration();
    conf.set(AccumuloHelper.USERNAME, "root");
    conf.set(AccumuloHelper.INSTANCE_NAME, "mock2");
    conf.set(AccumuloHelper.PASSWORD, noPasswordToken.toString());
    conf.set(AccumuloHelper.ZOOKEEPERS, i.getZooKeepers());
    conf.set(ShardedDataTypeHandler.METADATA_TABLE_NAME, TableName.METADATA);
    connector.tableOperations().create(conf.get(ShardedDataTypeHandler.METADATA_TABLE_NAME));
    BatchWriter recordWriter = connector.createBatchWriter(conf.get(ShardedDataTypeHandler.METADATA_TABLE_NAME), new BatchWriterConfig());
    // write a couiple of entries for multiple numshards
    Mutation m = new Mutation(NumShards.NUM_SHARDS);
    m.put(NumShards.NUM_SHARDS_CF + "blah", "20171102_19", "");
    recordWriter.addMutation(m);
    recordWriter.close();
    File multipleNumShardCache = File.createTempFile("numshards", ".txt");
    multipleNumShardCache.deleteOnExit();
    conf.set(ShardIdFactory.NUM_SHARDS, "11");
    conf.set(NumShards.ENABLE_MULTIPLE_NUMSHARDS, "true");
    conf.set(NumShards.MULTIPLE_NUMSHARDS_CACHE_PATH, multipleNumShardCache.getParent());
    AccumuloHelper mockedAccumuloHelper = EasyMock.createMock(AccumuloHelper.class);
    mockedAccumuloHelper.setup(conf);
    EasyMock.expectLastCall();
    EasyMock.expect(mockedAccumuloHelper.getConnector()).andReturn(connector);
    EasyMock.replay(mockedAccumuloHelper);
    NumShards numShards = new NumShards(conf);
    // these should create numshards.txt file based on multiple numshards entries in mock accumulo
    numShards.setaHelper(mockedAccumuloHelper);
    numShards.updateCache();
    assertEquals(11, numShards.getNumShards(0));
    assertEquals(11, numShards.getNumShards(Long.MAX_VALUE));
    assertEquals(11, numShards.getNumShards(""));
    assertEquals(11, numShards.getNumShards("20171102"));
    assertEquals(11, numShards.getMinNumShards());
    assertEquals(11, numShards.getMaxNumShards());
    assertEquals(1, numShards.getShardCount());
}
Also used : Connector(org.apache.accumulo.core.client.Connector) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Configuration(org.apache.hadoop.conf.Configuration) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) InMemoryInstance(datawave.accumulo.inmemory.InMemoryInstance) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) AccumuloHelper(datawave.ingest.data.config.ingest.AccumuloHelper) File(java.io.File) Test(org.junit.Test)

Example 2 with InMemoryInstance

use of datawave.accumulo.inmemory.InMemoryInstance in project datawave by NationalSecurityAgency.

the class NumShardsTest method testUpdateCache.

@Test
public void testUpdateCache() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, IOException, ParseException {
    // configure mock accumulo instance and populate with a couple of multiple numshards entries
    PasswordToken noPasswordToken = new PasswordToken();
    InMemoryInstance i = new InMemoryInstance("mock");
    Connector connector = i.getConnector("root", noPasswordToken);
    Configuration conf = new Configuration();
    conf.set(AccumuloHelper.USERNAME, "root");
    conf.set(AccumuloHelper.INSTANCE_NAME, "mock");
    conf.set(AccumuloHelper.PASSWORD, noPasswordToken.toString());
    conf.set(AccumuloHelper.ZOOKEEPERS, i.getZooKeepers());
    conf.set(ShardedDataTypeHandler.METADATA_TABLE_NAME, TableName.METADATA);
    connector.tableOperations().create(conf.get(ShardedDataTypeHandler.METADATA_TABLE_NAME));
    BatchWriter recordWriter = connector.createBatchWriter(conf.get(ShardedDataTypeHandler.METADATA_TABLE_NAME), new BatchWriterConfig());
    // write a couiple of entries for multiple numshards
    Mutation m = new Mutation(NumShards.NUM_SHARDS);
    m.put(NumShards.NUM_SHARDS_CF.toString(), "20170101_13", "");
    recordWriter.addMutation(m);
    m = new Mutation(NumShards.NUM_SHARDS);
    m.put(NumShards.NUM_SHARDS_CF.toString(), "20171101_17", "");
    recordWriter.addMutation(m);
    // invalid entry and should be ignored
    m = new Mutation(NumShards.NUM_SHARDS);
    m.put(NumShards.NUM_SHARDS_CF + "blah", "20171102_19", "");
    recordWriter.addMutation(m);
    recordWriter.close();
    File multipleNumShardCache = File.createTempFile("numshards", ".txt");
    multipleNumShardCache.deleteOnExit();
    conf.set(ShardIdFactory.NUM_SHARDS, "11");
    conf.set(NumShards.ENABLE_MULTIPLE_NUMSHARDS, "true");
    conf.set(NumShards.MULTIPLE_NUMSHARDS_CACHE_PATH, multipleNumShardCache.getParent());
    AccumuloHelper mockedAccumuloHelper = EasyMock.createMock(AccumuloHelper.class);
    mockedAccumuloHelper.setup(conf);
    EasyMock.expectLastCall();
    EasyMock.expect(mockedAccumuloHelper.getConnector()).andReturn(connector);
    EasyMock.replay(mockedAccumuloHelper);
    NumShards numShards = new NumShards(conf);
    // these should create numshards.txt file based on multiple numshards entries in mock accumulo
    numShards.setaHelper(mockedAccumuloHelper);
    numShards.updateCache();
    assertEquals(11, numShards.getNumShards(0));
    long cutoff = new SimpleDateFormat("yyyyMMdd").parse("20170101").getTime();
    assertEquals(11, numShards.getNumShards(cutoff - 1));
    assertEquals(13, numShards.getNumShards(cutoff));
    assertEquals(13, numShards.getNumShards(cutoff + 1));
    assertEquals(17, numShards.getNumShards(Long.MAX_VALUE));
    assertEquals(11, numShards.getNumShards(""));
    assertEquals(13, numShards.getNumShards("20170101"));
    assertEquals(13, numShards.getNumShards("20170102"));
    assertEquals(17, numShards.getNumShards("20171102"));
    assertEquals(11, numShards.getMinNumShards());
    assertEquals(17, numShards.getMaxNumShards());
    assertEquals(3, numShards.getShardCount());
}
Also used : Connector(org.apache.accumulo.core.client.Connector) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Configuration(org.apache.hadoop.conf.Configuration) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) InMemoryInstance(datawave.accumulo.inmemory.InMemoryInstance) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) AccumuloHelper(datawave.ingest.data.config.ingest.AccumuloHelper) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 3 with InMemoryInstance

use of datawave.accumulo.inmemory.InMemoryInstance in project datawave by NationalSecurityAgency.

the class MetricsTableConfigHelperTest method setUp.

@Before
public void setUp() throws Exception {
    tops = new InMemoryInstance().getConnector("user", new PasswordToken("pass")).tableOperations();
    String tableName = MetricsConfiguration.getTable(conf);
    tops.create(tableName);
    configHelper = new MetricsTableConfigHelper();
    configHelper.setup(tableName, conf, logger);
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) InMemoryInstance(datawave.accumulo.inmemory.InMemoryInstance) Before(org.junit.Before)

Example 4 with InMemoryInstance

use of datawave.accumulo.inmemory.InMemoryInstance in project datawave by NationalSecurityAgency.

the class AccumuloIndexAgeDisplayTest method setup.

@Before
public void setup() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException {
    // set hadoop.home.dir so we don't get an IOException about it. Doesn't appear to be used though
    System.setProperty("hadoop.home.dir", "/tmp");
    // May need to replace InMemoryInstance with MiniCluster. Apparently InMemoryInstance isn't kept up as well.
    mockInstance = new InMemoryInstance();
    conn = mockInstance.getConnector(userName, password);
    conn.securityOperations().changeUserAuthorizations(userName, auths);
    conn.tableOperations().create(tableName);
}
Also used : InMemoryInstance(datawave.accumulo.inmemory.InMemoryInstance) Before(org.junit.Before)

Example 5 with InMemoryInstance

use of datawave.accumulo.inmemory.InMemoryInstance in project datawave by NationalSecurityAgency.

the class MockTableTest method setup.

@Before
public void setup() throws AccumuloSecurityException, AccumuloException, TableNotFoundException, TableExistsException {
    InMemoryInstance i = new InMemoryInstance(this.getClass().toString());
    connector = i.getConnector("root", new PasswordToken(""));
    if (connector.tableOperations().exists(TABLE_NAME))
        connector.tableOperations().delete(TABLE_NAME);
    connector.tableOperations().create(TABLE_NAME);
    writer = createBatchWriter();
    tableOperations = connector.tableOperations();
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) InMemoryInstance(datawave.accumulo.inmemory.InMemoryInstance) Before(org.junit.Before)

Aggregations

InMemoryInstance (datawave.accumulo.inmemory.InMemoryInstance)31 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)19 Connector (org.apache.accumulo.core.client.Connector)18 Test (org.junit.Test)13 Authorizations (org.apache.accumulo.core.security.Authorizations)11 BeforeClass (org.junit.BeforeClass)11 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)8 Value (org.apache.accumulo.core.data.Value)7 Text (org.apache.hadoop.io.Text)6 HashMultimap (com.google.common.collect.HashMultimap)5 Multimap (com.google.common.collect.Multimap)5 RawRecordContainerImpl (datawave.ingest.config.RawRecordContainerImpl)5 RawRecordContainer (datawave.ingest.data.RawRecordContainer)5 Type (datawave.ingest.data.Type)5 NormalizedContentInterface (datawave.ingest.data.config.NormalizedContentInterface)5 BulkIngestKey (datawave.ingest.mapreduce.job.BulkIngestKey)5 IvaratorCacheDirConfig (datawave.query.iterator.ivarator.IvaratorCacheDirConfig)5 MockStatusReporter (datawave.query.testframework.MockStatusReporter)5 DatawavePrincipal (datawave.security.authorization.DatawavePrincipal)5 DatawaveUser (datawave.security.authorization.DatawaveUser)5