JACOB - ALM OTA connection - How to retrieve the list of testsets - jacob

I am trying to get list of testsets using JACOB- ALM connection.
I am using below code to establish connection.
Dispatch.call(disp, "InitConnectionEx", "url");
Dispatch.call(disp, "Login", "user","password");
Dispatch.call(disp, "Connect", "Domain","Project");
Can someone suggest me code to connect to testlab and get the details from testset?

What you need is the TestSetTreeManager. It has a method FindTestSets which gets you a list of test sets. Some example:
private static void printTestSetNamesFromFolder(String testLabPath)
{
Dispatch treeManager = Dispatch.get(disp, "TestSetTreeManager").toDispatch();
Dispatch testLabFolder = Dispatch.call(treeManager, "NodeByPath", testLabPath).toDispatch();
Dispatch testSets = Dispatch.call(testLabFolder, "FindTestSets", "").getDispatch();
EnumVariant testSetsList = new EnumVariant(testSets);
while (testSetsList.hasMoreElements())
{
Dispatch testSet = testSetsList.nextElement().getDispatch();
System.out.println(Dispatch.get(testSet, "Name").getString());
}
}
I am new to Jacob, so I don't exactly know when to use get() or call() or toDispatch() or getDispatch() but the example should work fine.

Related

Asynchronous hive query execution : OperationHandle gets cleaned up at server side as soon as the query initiator client disconnects

Is it possible to execute a query asynchronously in hive server?
For eg, How can I /Is it possible to do something like this from the client-
QueryHandle handle = executeAsyncQuery(hiveQuery);
Status status = handle.checkStatus();
if(status.isCompleted()) {
QueryResult result = handle.fetchResult();
}
I also had a look at How do I make an async call to Hive in Java?. But did not help. The answers were mostly around the thrift clients taking a callback argument.
Any help would be appreciated. Thanks!
[EDIT 1]
I went through the HiveConnection.java in hive-jdbc. hive-jdbc by default uses the async thrift APIs. Hence it submits a query and polls for result sets (look at HiveStatement.java). Now i am able to write a piece of code which is purely non blocking. But the problem is as soon as the client disconnect the foot print about the query is lost.
Client 1
final TCLIService.Client client = new TCLIService.Client(createBinaryTransport(host, port, loginTimeout, sessConf, false)); // from HiveConnection.java
TSessionHandle sessionHandle = openSession(client) // from HiveConnection.java
TExecuteStatementReq execReq = new TExecuteStatementReq(sessionHandle, sql);
execReq.setRunAsync(true);
execReq.setConfOverlay(sessConf);
final TGetOperationStatusReq handle = client.ExecuteStatement(execReq)
writeHandleToFile("~/handle", handle)
Client 2
final TGetOperationStatusReq handle = readHandleFromFile("~/handle")
final TCLIService.Client client = new TCLIService.Client(createBinaryTransport(host, port, loginTimeout, sessConf, false));
while (true) {
System.out.println(client.GetOperationStatus(handle).getOperationState());
Thread.sleep(1000);
}
Client 2 keeps printing FINISHED_STATE as long as Client 1 is alive. But if client 1 process completes or gets killed, client 2 starts printing null which means hiveserver2 is cleaning up the resources as soon as a client disconnects.
Is it possible to configure hiveserver2 to configure this clean up process based on time or something?
Thanks!
Did some research and figured out that this happens only with binary transport (tcp)
#Override
public void deleteContext(ServerContext serverContext,
TProtocol input, TProtocol output) {
Metrics metrics = MetricsFactory.getInstance();
if (metrics != null) {
try {
metrics.decrementCounter(MetricsConstant.OPEN_CONNECTIONS);
} catch (Exception e) {
LOG.warn("Error Reporting JDO operation to Metrics system", e);
}
}
ThriftCLIServerContext context = (ThriftCLIServerContext) serverContext;
SessionHandle sessionHandle = context.getSessionHandle();
if (sessionHandle != null) {
LOG.info("Session disconnected without closing properly, close it now");
try {
cliService.closeSession(sessionHandle);
} catch (HiveSQLException e) {
LOG.warn("Failed to close session: " + e, e);
}
}
}
The above stub (from ThriftBinaryCLIService) gets executed through this piece of code from TThreadPoolServer which is used by ThriftBinaryCLIService.
eventHandler.deleteContext(connectionContext, inputProtocol,
outputProtocol);
Apparently http transport (ThriftHttpCLIService) has a different strategy of cleaning up operation handles (not greedy like tcp)
Will check with hive community on this to understand a bit more and see if there is an issue addressing this already.

Calling other functions inside Lambda [C++/CX]

I'm working on a Windows Store app (C++). The app loads data from database using a webservice and I want that data to be shown on the page.
Why can I not call functions w.r.t an instance of a class created inside the enclosing function? Here's the LoadState event of my app's first page...
void ItemsPage::LoadState(Object^ navigationParameter, IMap<String^, Object^>^ pageState)
{
(void) pageState;
StorySource^ storysource = ref new StorySource();
task<wstring> (GetFromDB(cancellationTokenSource.get_token()))
.then([this, storysource](task<wstring> response){
try
{
auto resp = response.get();
storysource->Init(resp);
DefaultViewModel->Insert("Items", storysource->AllGroups);
}
catch(COMException^ ex)
{ ... }
});
}
I can't execute any function inside the .then() block. I need to somehow chain the completion of GetFromDB() to StorySource::Init() and this to DefaultViewModel->Insert().
I am very new to asynchronous programming. Please explain me what I am doing wrong and what could be the solution to my problem. Thanks in advance.

How can I write a unit test against a WebPartBase class and mock out the controls?

I have a bunch of WebPartBase classes that I'm trying to invoke a method on. Some of the methods call controls on the UI. I want to stub out those controls somehow so that an exception doesn't get thrown when attempting to set values on them. Does anyone know of a good way to do this? It would also be fine if they were initialized but I'm not sure how to initialize them without running a web server.
My test code looks like this. IntializeOnAdd() is a method on KPIWebPartBase and KPIWebPartBase inherits from WebPartBase.
[TestMethod]
public void InvokeAllWidgets()
{
var user = new User("adminqaphi");
user.CustomerID = TestConfig.ClientID;
var classes = typeof(KPIWebPartBase)
.Assembly
.GetTypes()
.Where(t => t.IsSubclassOf(typeof(KPIWebPartBase)) && !t.IsAbstract );
foreach (var c in classes)
{
Console.WriteLine(c.Name);
var instance = (KPIWebPartBase)Activator.CreateInstance(c);
foreach (var billingMetric in Enum.GetValues(typeof(BillingMetric)))
{
instance.CurrentUser = user;
instance.BillingMetric = (BillingMetric)billingMetric;
if (instance is StartEndKPIWebPartBase)
{
var startEndKPI = (StartEndKPIWebPartBase)instance;
startEndKPI.StartDate = new DateTime(2007, 1, 1);
startEndKPI.EndDate = new DateTime(2008, 1, 1);
}
instance.InitializeOnAdd();
}
}
}
I would create interfaces for them (if possible) and use moq to create Mocks or stubs for the external dependencies.
What behavior does InvokeAllWidgets() test?
Response to comment:
I think you should mock the database as well, so that you just test the "internal" logic of the code(unit). Otherwise you will en up testing the database, and I guess that is not what you want to. And if you do call the database, what happens if some data in it changes? Will that fail your tests? If so I think you are doing integration tests and not unit tests. In a unit test try to mock all external dependencies and test your own logic (what can go wrong?). If your code don't allow you test it like, then change it!

What hinders NetStream.onPeerConnect from being triggered?

I'm using Adobe Stratus (now renamed to Cirrus) to build a p2p application. Inside the application, I used NetStream.onPeerConnect callback function and expected it to be triggered every time when a peer is connected. However, it always failed with my friend A while strangely friend B managed to have the function called without any problem.
I was wondering what could be the cause to this issue?
Here are how the code pieces look like.
First of all, create a NetConnection.
netConnection = new NetConnection();
netConnection.addEventListener(NetStatusEvent.NET_STATUS, netConnectionHandler);
netConnection.connect(SERVER_ADDRESS+DEVELOPER_KEY);
Secondly, create NetStream upon NetConnection successfully connected.
private function netConnectionHandler(event:NetStatusEvent):void{
switch (event.info.code){
case "NetConnection.Connect.Success":
sendStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
sendStream.addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler);
var sendObj:Object = new Object();
sendObj.onPeerConnect = function(subscriber:NetStream) : Boolean {
trace("[onPeerConnect] far id: " + subscriber.farID);
return true;
}
sendStream.client = sendObj;
sendStream.publish("file");
......
Thirdly, here's how I build the connection between two peers
receivedStream = new NetStream(netConnection, farId);
receivedStream.client = this;
receivedStream.addEventListener(NetStatusEvent.NET_STATUS, incomingStreamHandler);
receivedStream.play("file");
Please help enlighten me. Thanks!
It turns out my friend A is behind a symmetric NAT. I'm thinking to setup a TURN server for us to build a successful connection.

structureMap mocks stub help

I have an BLL that does validation on user input then inserts a parent(PorEO) and then inserts children(PorBoxEO). So there are two calls to the same InsertJCDC. One like this=>InsertJCDC(fakePor) and another like this=>InsertJCDC(fakeBox).
When I stub out the parent I want to return fakePor. But when I run the code it returns null instead. Here is the unit test.
[Test]
public void PorBLL_InsertByPorInsertCV_DoingGoodCase()
{
// Startup object mapper
_Bootstrapper.Bootstrap();
// create the mock for generic Crud
IGenericCrud mockGenericCrud = MockRepository.GenerateMock<IGenericCrud>();
PorInsertCV fakePor = new PorInsertCV();
PorBoxInsertCV fakeBox = new PorBoxInsertCV();
// build fake return
PorEO fakePorNewRow = new PorEO();
fakePorNewRow.PorId = 22;
// stub parent and child insert routines.
mockGenericCrud.Stub(c => c.InsertJCDC<PorEO, PorInsertCV>(fakePor)).Return(fakePorNewRow);
mockGenericCrud.Stub(c => c.InsertJCDC<PorBoxEO, PorBoxInsertCV>(fakeBox)).Return(null);
ObjectFactory.Inject(typeof(IGenericCrud), mockGenericCrud);
IPorBLL localWithMock = ObjectFactory.GetInstance<IPorBLL>();
// build user args to csll bll with and use for insert
PorInsertCV userArgs = new PorInsertCV();
userArgs.AccessionNbr = "364-80-0007";
userArgs.NbrBoxes = 11;
userArgs.RegId = 20;
userArgs.TransmitedDt = Convert.ToDateTime("1/30/1980");
// call the bll using the stub
localWithMock.InsertByPorInsertCV(userArgs);
}
Any help is greatly appreciated
I can't really follow your code that well, but I'll give it a shot.
From my skills of deduction, this line here is the one giving you issues:
mockGenericCrud.Stub(c => c.InsertJCDC<PorEO, PorInsertCV>(fakePor)).Return(fakePorNewRow);
Because you're expecting fakePorNewRow to be returned when you call localWithMock.InsertByPorInsertCV(userArgs); - yeah?
If that's your case, what your problem is, is that it will only return fakePorNewRow when it is given fakePor ... not userArgs as you have given it.
Tell me if I'm completely off track.
HTHs,
Charles
Ps. You might want to add the tag of which mocking framework you are using to the question.

Resources