HWIAuth user1 = new HWIAuth();
user1.setUser("hadoop");
user1.setGroups(new String[] { "hadoop" });
// create two sessions for user
HWISessionItem user1_item1 = hsm.createSession(user1, "session1");
HWISessionItem user1_item2 = hsm.createSession(user1, "session2");
// create second user
HWIAuth user2 = new HWIAuth();
user2.setUser("user2");
user2.setGroups(new String[] { "user2" });
// create one session for this user
HWISessionItem user2_item1 = hsm.createSession(user2, "session1");
// testing storage of sessions in HWISessionManager
assertEquals(hsm.findAllSessionsForUser(user1).size(), 2);
assertEquals(hsm.findAllSessionsForUser(user2).size(), 1);
assertEquals(hsm.findAllSessionItems().size(), 3);
HWISessionItem searchItem = hsm.findSessionItemByName(user1, "session1");
assertEquals(searchItem, user1_item1);
searchItem.addQuery("create table " + tableName
+ " (key int, value string)");
searchItem.addQuery("describe "+tableName);
searchItem.clientStart();
// wait for the session manager to make the table. It is non blocking API.
synchronized (searchItem.runnable ) {
while (searchItem.getStatus() != HWISessionItem.WebSessionItemStatus.READY) {
searchItem.runnable.wait();
}
}
ArrayList<Integer> zero = new ArrayList<Integer>(); zero.add(0); zero.add(0); zero.add(0); zero.add(0);
ArrayList<Integer> zero3 = new ArrayList<Integer>(); zero3.add(0); zero3.add(0); zero3.add(0);
ArrayList<Integer> zero1 = new ArrayList<Integer>(); zero1.add(0);
assertEquals( zero , searchItem.getQueryRet());
Vector<Vector<String>> searchBlockRes = searchItem.getResultBucket();
String resLine = searchBlockRes.get(0).get(0) ;
assertEquals(true, resLine.contains("key") );
assertEquals(true, resLine.contains("int") );
String resLine2= searchBlockRes.get(0).get(1) ;
assertEquals(true, resLine2.contains("value") );
assertEquals(true, resLine2.contains("string") );
// load data into table
searchItem.clientRenew();
searchItem.addQuery("load data local inpath '" + dataFilePath.toString()
+ "' into table " + tableName);
searchItem.clientStart();
while (searchItem.getStatus() != HWISessionItem.WebSessionItemStatus.READY) {
Thread.sleep(1);
}
assertEquals(zero1 , searchItem.getQueryRet());
// start two queries simultaniously
user1_item2.addQuery("select distinct(test_hwi_table.key) from "
+ tableName);
user2_item1.addQuery("select distinct(test_hwi_table.key) from "
+ tableName);
// set result files to compare results
File tmpdir = new File("/tmp/" + System.getProperty("user.name") + "/");
if (tmpdir.exists() && !tmpdir.isDirectory()) {
throw new RuntimeException(tmpdir + " exists but is not a directory");
}
if (!tmpdir.exists()) {
if (!tmpdir.mkdirs()) {
throw new RuntimeException("Could not make scratch directory " + tmpdir);
}
}
File result1 = new File(tmpdir, "user1_item2");
File result2 = new File(tmpdir, "user2_item1");
user1_item2.setResultFile(result1.toString());
user2_item1.setResultFile(result2.toString());
user1_item2.setSSIsSilent(true);
user2_item1.setSSIsSilent(true);
user1_item2.clientStart();
user2_item1.clientStart();
synchronized (user1_item2.runnable) {
while (user1_item2.getStatus() != HWISessionItem.WebSessionItemStatus.READY) {
user1_item2.runnable.wait();
}
}
synchronized (user2_item1.runnable) {
while (user2_item1.getStatus() != HWISessionItem.WebSessionItemStatus.READY) {
user2_item1.runnable.wait();
}
}
assertEquals(zero3 , user1_item2.getQueryRet() );
assertEquals(zero3 , user2_item1.getQueryRet() );
assertEquals(true , isFileContentEqual(result1, result2));
// clean up the files
result1.delete();
result2.delete();
// test a session renew/refresh
user2_item1.clientRenew();
user2_item1.addQuery("select distinct(test_hwi_table.key) from "
+ tableName);
user2_item1.clientStart();
synchronized (user2_item1.runnable ) {
while (user2_item1.getStatus() != HWISessionItem.WebSessionItemStatus.READY) {
user2_item1.runnable.wait();
}
}
// cleanup
HWISessionItem cleanup = hsm.createSession(user1, "cleanup");
cleanup.addQuery("drop table " + tableName);
cleanup.clientStart();
synchronized (cleanup.runnable) {
while (cleanup.getStatus() != HWISessionItem.WebSessionItemStatus.READY) {
cleanup.runnable.wait();
}
}
// test the history is non null object.
HiveHistoryViewer hhv = cleanup.getHistoryViewer();
assertNotNull(hhv);
assertEquals( zero3 , cleanup.getQueryRet() );
}