Topic
  • 5 replies
  • Latest Post - ‏2013-04-01T12:08:46Z by SystemAdmin
SystemAdmin
SystemAdmin
5507 Posts

Pinned topic Update DataPool using Custom Code in Rational Performance Tester / Hyades?

‏2012-12-17T07:58:50Z |
Hi,

taken this tutorial(http://www.ibm.com/developerworks/rational/library/programmatically-modify-rational-datapools/index.html) I've created a custom code in order to update a data pool with data taken from a http response in order to pass data (session key) to all subsequent requests.

Unfortunately the tutorial is now valid for RPT 8.3 anymore since it uses a newer version of Hyades. Additionally I didn't find any further documentation on modifying data pools.

The code taken from the tutorial above does not compile anymore. This is the code I'm using:




package playground;   

import java.io.File;   

import org.eclipse.hyades.edit.datapool.IDatapool; 

import org.eclipse.hyades.edit.datapool.IDatapoolFactory; 

import org.eclipse.hyades.execution.runtime.datapool.DatapoolException; 

import org.eclipse.hyades.execution.runtime.datapool.IDatapoolIterator; 

import org.eclipse.hyades.models.common.datapool.impl.Common_DatapoolFactoryImpl;   

public 

class Test 
{ 

public 

static 

void main(String args[]) 
{ 
// set the Datapool File value String dataPoolFile=
"sunbay/SessionId.datapool"; File inputTptpFile = 

new File( dataPoolFile); System.out.println(
"Read a TPTP (RPT/RST) format Datapool: " + inputTptpFile.getAbsolutePath());   StringBuilder aStringBuilder = 

new StringBuilder(); 

try 
{ 
// create an IDatapoolFactory object IDatapoolFactory tptpDatapoolFactory = 

new Common_DatapoolFactoryImpl(); 
// create an Datapool object IDatapool tptpDatapool = (IDatapool) tptpDatapoolFactory.loadForEdit( inputTptpFile, 

true);   
// capture the Datapool column header values 

int datapoolColumnCount = tptpDatapool.getVariableCount(); String[] header = 

new String[datapoolColumnCount]; aStringBuilder.append(
"\nHEADER  :: "); 

for (

int i = 0; i < datapoolColumnCount; i++) 
{ header[i] = tptpDatapool.getVariable(i).getName(); aStringBuilder.append(header[i] + 
" :: "); 
} System.out.println(aStringBuilder.toString());   
// Create an IDatapoolIterator object and populate with 
// the Datapool as an iterator IDatapoolIterator tptpDatapoolIterator = tptpDatapoolFactory . loadForEdit(inputTptpFile, 

true); 
//                     IDatapoolIterator tptpDatapoolIterator = tptpDatapoolFactory 
//                                  . open(tptpDatapool, 
//                                                  "org.eclipse.hyades.datapool.iterator.DatapoolIteratorSequentialPrivate");   
// initialize datapool iterator tptpDatapoolIterator.dpInitialize(tptpDatapool, 0); 

int count = 1; 
// int counter for demonstration purposes only 

while (!tptpDatapoolIterator.dpDone()) 
{ 
// reset the temporary container for captured values aStringBuilder.setLength(0); aStringBuilder.append(
"ROW #" + count + 
"  :: "); String[] nextRow = 

new String[datapoolColumnCount]; 

for (

int i = 0; i < datapoolColumnCount; i++) 
{ 
/* * NOTE: this example assumes value to be of type String * value can be captured via: * IDatapool.getVariable(int).getSuggestedType() */ nextRow[i] = tptpDatapoolIterator.dpCurrent() .getCell(header[i]).getStringValue(); aStringBuilder.append(nextRow[i] + 
" :: "); 
} tptpDatapoolIterator.dpNext(); count++; System.out.println(aStringBuilder.toString()); 
// unload the Datapool tptpDatapoolFactory.unload(tptpDatapool); 
} 
} 

catch (DatapoolException e) 
{ e.printStackTrace(); 
} 
} 
}


Unfortunately the following line doesn't compile anymore:


IDatapoolIterator tptpDatapoolIterator = tptpDatapoolFactory . open(tptpDatapool, 
"org.eclipse.hyades.datapool.iterator.DatapoolIteratorSequentialPrivate");


So how do I get an iterator over a DataPool object?

Best Regards,

Romeo


Romeo Kienzler
Technical Consultant @IBM Innovation Center Zurich
http://www.linkedin.com/pub/romeo-kienzler/57/b45/89

Updated on 2013-04-01T12:08:46Z at 2013-04-01T12:08:46Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    5507 Posts

    Re: Update DataPool using Custom Code in Rational Performance Tester / Hyades?

    ‏2012-12-17T14:21:29Z  
    If the line which doesn't compile is replaced with the following, it seems to be compiling fine. (Seems like some changes in the API)

    DatapoolIteratorSequentialPrivate tptpDatapoolIterator;
    tptpDatapoolIterator.dpInitialize(tptpDatapool);

    After this, tptpDatapoolIterator should be set for use.

    (import org.eclipse.hyades.datapool.iterator.DatapoolIteratorSequentialPrivate) at the top as well.
  • petersda
    petersda
    404 Posts

    Re: Update DataPool using Custom Code in Rational Performance Tester / Hyades?

    ‏2012-12-17T14:34:50Z  
    Instead of putting this value in a datapool, I think it would be much easier to just substitute the value directly into the request. The way I recommend accomplishing this is :
    1. find a request that has the sessionid.
    2. Highlight the session id, right click, Create Substitution site.
    3. When asked to pick a reference make sure to select find Potential sites.
    4. Find the session id in the response and select it. This will create a reference.
    5. You will be prompted to find all other substitution sites. Say yes.

    This should get all requests in your test to be substituted from that session id.
  • SystemAdmin
    SystemAdmin
    5507 Posts

    Re: Update DataPool using Custom Code in Rational Performance Tester / Hyades?

    ‏2012-12-17T16:07:09Z  
    Dear Arun,

    your code compiles fine but IMHO will raise a NullPointerException, so I've cheated a bit:

    
    IDatapoolIterator tptpDatapoolIterator = 
    
    new DatapoolIteratorSequentialPrivate(); tptpDatapoolIterator.dpInitialize(tptpDatapool);
    


    So this works for me now, for updating the DataPool value I use:

    
    IDatapoolCell aCell = (IDatapoolCell) tptpDatapoolIterator .dpCurrent().getCell(
    "SessionID"); aCell.setCellValue(sessionId); tptpDatapoolFactory.save(tptpDatapool); tptpDatapoolFactory.unload(tptpDatapool);
    


    @Peter: Thanks for your suggesting, but the problem is that I need to re-send the session-ID the server creates for me in all subsequent requests. So I have to somehow store this intermediate value.

    Best Regards,

    Romeo

    Romeo Kienzler
    Technical Consultant @IBM Innovation Center Zurich
    http://www.linkedin.com/pub/romeo-kienzler/57/b45/89

  • petersda
    petersda
    404 Posts

    Re: Update DataPool using Custom Code in Rational Performance Tester / Hyades?

    ‏2012-12-17T16:16:04Z  
    Dear Arun,

    your code compiles fine but IMHO will raise a NullPointerException, so I've cheated a bit:

    <pre class="jive-pre"> IDatapoolIterator tptpDatapoolIterator = new DatapoolIteratorSequentialPrivate(); tptpDatapoolIterator.dpInitialize(tptpDatapool); </pre>

    So this works for me now, for updating the DataPool value I use:

    <pre class="jive-pre"> IDatapoolCell aCell = (IDatapoolCell) tptpDatapoolIterator .dpCurrent().getCell( "SessionID"); aCell.setCellValue(sessionId); tptpDatapoolFactory.save(tptpDatapool); tptpDatapoolFactory.unload(tptpDatapool); </pre>

    @Peter: Thanks for your suggesting, but the problem is that I need to re-send the session-ID the server creates for me in all subsequent requests. So I have to somehow store this intermediate value.

    Best Regards,

    Romeo

    Romeo Kienzler
    Technical Consultant @IBM Innovation Center Zurich
    http://www.linkedin.com/pub/romeo-kienzler/57/b45/89

    I'm not sure I understand what the problem is you are trying to solve. Do you mean you need this value in a different test? If so, you can save this value in a variable and the next test can have its requests be substituted from the variable.

    If you are talking about in one test, when we create the reference we store the value and all subsequent requests its substituted into will use the value.

    One last thing.... I am also unsure of the behavior when you edit a datapool from custom code. This is not a supported use case within rpt.
  • SystemAdmin
    SystemAdmin
    5507 Posts

    Re: Update DataPool using Custom Code in Rational Performance Tester / Hyades?

    ‏2013-04-01T12:08:46Z  
    hi,

    i have one business scenario like one user uploading the file ,the status of the file is "Ready",this is one
    test case,the another testcase is the same user has to login again and proceed the file for status called
    "process",the probelm i am facing here is mapping the user with file name
    ex:

    datapool have 5 user like user1,user2,user3,user4,user5,each user uploading some 3 files
    user1 uploading file like a.txt,b.txt,c.txt;
    user2 uploading file like d.txt,e.txt,f.txt;
    user3 uploading file like g.txt,i.txt,j.txt;
    user4 uploading file like k.txt,l.txt,m.txt;
    user5 uploading file like n.txt,o.txt,p.txt;

    if user3 login he has access only his file called g.txt,i.txt,j.txt,user name will be in different
    datapool,file name will be in different datapool

    please help me

    thanks