use of org.apache.accumulo.core.client.mock.MockInstance in project hive by apache.
the class TestAccumuloStorageHandler method testRollbackCreateTableDeletesExistentTable.
@Test()
public void testRollbackCreateTableDeletesExistentTable() throws Exception {
MockInstance inst = new MockInstance(test.getMethodName());
Connector conn = inst.getConnector("root", new PasswordToken(""));
AccumuloStorageHandler storageHandler = Mockito.mock(AccumuloStorageHandler.class);
String tableName = "table";
// Create the table
conn.tableOperations().create(tableName);
AccumuloConnectionParameters connectionParams = Mockito.mock(AccumuloConnectionParameters.class);
Table table = Mockito.mock(Table.class);
// Call the real preCreateTable method
Mockito.doCallRealMethod().when(storageHandler).rollbackCreateTable(table);
Mockito.doCallRealMethod().when(storageHandler).commitDropTable(table, true);
// Return our known table name
Mockito.when(storageHandler.getTableName(table)).thenReturn(tableName);
// Is not an EXTERNAL table
Mockito.when(storageHandler.isExternalTable(table)).thenReturn(false);
// Return the MockInstance's Connector
Mockito.when(connectionParams.getConnector()).thenReturn(conn);
storageHandler.connectionParams = connectionParams;
storageHandler.rollbackCreateTable(table);
Assert.assertFalse(conn.tableOperations().exists(tableName));
}
use of org.apache.accumulo.core.client.mock.MockInstance in project hive by apache.
the class TestAccumuloStorageHandler method testDropTableWithoutDeleteLeavesTableIntact.
@Test
public void testDropTableWithoutDeleteLeavesTableIntact() throws Exception {
MockInstance inst = new MockInstance(test.getMethodName());
Connector conn = inst.getConnector("root", new PasswordToken(""));
AccumuloStorageHandler storageHandler = Mockito.mock(AccumuloStorageHandler.class);
String tableName = "table";
// Create the table
conn.tableOperations().create(tableName);
AccumuloConnectionParameters connectionParams = Mockito.mock(AccumuloConnectionParameters.class);
Table table = Mockito.mock(Table.class);
// Call the real preCreateTable method
Mockito.doCallRealMethod().when(storageHandler).commitDropTable(table, false);
// Return our known table name
Mockito.when(storageHandler.getTableName(table)).thenReturn(tableName);
// Is not an EXTERNAL table
Mockito.when(storageHandler.isExternalTable(table)).thenReturn(false);
// Return the MockInstance's Connector
Mockito.when(connectionParams.getConnector()).thenReturn(conn);
storageHandler.connectionParams = connectionParams;
storageHandler.rollbackCreateTable(table);
Assert.assertTrue(conn.tableOperations().exists(tableName));
}
use of org.apache.accumulo.core.client.mock.MockInstance in project hive by apache.
the class TestAccumuloStorageHandler method testExternalNonExistentTableFails.
@Test(expected = MetaException.class)
public void testExternalNonExistentTableFails() throws Exception {
MockInstance inst = new MockInstance(test.getMethodName());
Connector conn = inst.getConnector("root", new PasswordToken(""));
String tableName = "table";
// Define the SerDe Parameters
Map<String, String> params = new HashMap<String, String>();
params.put(AccumuloSerDeParameters.COLUMN_MAPPINGS, "cf:cq");
AccumuloConnectionParameters connectionParams = Mockito.mock(AccumuloConnectionParameters.class);
AccumuloStorageHandler storageHandler = Mockito.mock(AccumuloStorageHandler.class);
StorageDescriptor sd = Mockito.mock(StorageDescriptor.class);
Table table = Mockito.mock(Table.class);
SerDeInfo serDeInfo = Mockito.mock(SerDeInfo.class);
// Call the real preCreateTable method
Mockito.doCallRealMethod().when(storageHandler).preCreateTable(table);
// Return our known table name
Mockito.when(storageHandler.getTableName(table)).thenReturn(tableName);
// Is an EXTERNAL table
Mockito.when(storageHandler.isExternalTable(table)).thenReturn(true);
// Return the mocked StorageDescriptor
Mockito.when(table.getSd()).thenReturn(sd);
// No location expected with AccumuloStorageHandler
Mockito.when(sd.getLocation()).thenReturn(null);
// Return mocked SerDeInfo
Mockito.when(sd.getSerdeInfo()).thenReturn(serDeInfo);
// Custom parameters
Mockito.when(serDeInfo.getParameters()).thenReturn(params);
// Return the MockInstance's Connector
Mockito.when(connectionParams.getConnector()).thenReturn(conn);
storageHandler.connectionParams = connectionParams;
storageHandler.preCreateTable(table);
}
use of org.apache.accumulo.core.client.mock.MockInstance in project hive by apache.
the class TestAccumuloStorageHandler method testMissingColumnMappingFails.
@Test(expected = MetaException.class)
public void testMissingColumnMappingFails() throws Exception {
MockInstance inst = new MockInstance(test.getMethodName());
Connector conn = inst.getConnector("root", new PasswordToken(""));
String tableName = "table";
// Empty parameters are sent, no COLUMN_MAPPING
Map<String, String> params = new HashMap<String, String>();
AccumuloConnectionParameters connectionParams = Mockito.mock(AccumuloConnectionParameters.class);
AccumuloStorageHandler storageHandler = Mockito.mock(AccumuloStorageHandler.class);
StorageDescriptor sd = Mockito.mock(StorageDescriptor.class);
Table table = Mockito.mock(Table.class);
SerDeInfo serDeInfo = Mockito.mock(SerDeInfo.class);
// Call the real preCreateTable method
Mockito.doCallRealMethod().when(storageHandler).preCreateTable(table);
// Return our known table name
Mockito.when(storageHandler.getTableName(table)).thenReturn(tableName);
// Not an EXTERNAL table
Mockito.when(storageHandler.isExternalTable(table)).thenReturn(false);
// Return the mocked StorageDescriptor
Mockito.when(table.getSd()).thenReturn(sd);
// No location expected with AccumuloStorageHandler
Mockito.when(sd.getLocation()).thenReturn(null);
// Return mocked SerDeInfo
Mockito.when(sd.getSerdeInfo()).thenReturn(serDeInfo);
// Custom parameters
Mockito.when(serDeInfo.getParameters()).thenReturn(params);
// Return the MockInstance's Connector
Mockito.when(connectionParams.getConnector()).thenReturn(conn);
storageHandler.connectionParams = connectionParams;
storageHandler.preCreateTable(table);
}
use of org.apache.accumulo.core.client.mock.MockInstance in project hive by apache.
the class TestAccumuloStorageHandler method testPreCreateTable.
@Test
public void testPreCreateTable() throws Exception {
MockInstance inst = new MockInstance(test.getMethodName());
Connector conn = inst.getConnector("root", new PasswordToken(""));
String tableName = "table";
// Define the SerDe Parameters
Map<String, String> params = new HashMap<String, String>();
params.put(AccumuloSerDeParameters.COLUMN_MAPPINGS, "cf:cq");
AccumuloConnectionParameters connectionParams = Mockito.mock(AccumuloConnectionParameters.class);
AccumuloStorageHandler storageHandler = Mockito.mock(AccumuloStorageHandler.class);
StorageDescriptor sd = Mockito.mock(StorageDescriptor.class);
Table table = Mockito.mock(Table.class);
SerDeInfo serDeInfo = Mockito.mock(SerDeInfo.class);
// Call the real preCreateTable method
Mockito.doCallRealMethod().when(storageHandler).preCreateTable(table);
// Return our known table name
Mockito.when(storageHandler.getTableName(table)).thenReturn(tableName);
// Not an EXTERNAL table
Mockito.when(storageHandler.isExternalTable(table)).thenReturn(false);
// Return the mocked StorageDescriptor
Mockito.when(table.getSd()).thenReturn(sd);
// No location expected with AccumuloStorageHandler
Mockito.when(sd.getLocation()).thenReturn(null);
// Return mocked SerDeInfo
Mockito.when(sd.getSerdeInfo()).thenReturn(serDeInfo);
// Custom parameters
Mockito.when(serDeInfo.getParameters()).thenReturn(params);
// Return the MockInstance's Connector
Mockito.when(connectionParams.getConnector()).thenReturn(conn);
storageHandler.connectionParams = connectionParams;
storageHandler.preCreateTable(table);
Assert.assertTrue("Table does not exist when we expect it to", conn.tableOperations().exists(tableName));
}
Aggregations