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());
}
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());
}
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);
}
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);
}
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();
}
Aggregations