Tuesday, March 16, 2010

Too many open files error / opened file checker

#!/bin/bash
COUNTER=0
HOW_MANY=0
MAX=0
# do not take care about COUNTER - just flag, shown should we continue or not
while [ $COUNTER -lt 10 ]; do
    #run until process with passed pid alive
    if [ -r "/proc/$1" ]; then
        # count, how many files we have
        HOW_MANY=`/usr/sbin/lsof -p $1 | wc -l`
        #output for live monitoring
        echo `date +%H:%M:%S` $HOW_MANY
        # uncomment, if you want to save statistics
        #/usr/sbin/lsof -p $1 > ~/autocount/config_lsof_`echo $HOW_MANY`_`date +%H_%M_%S`.txt

        # look for max value
        if [ $MAX -lt $HOW_MANY ]; then
                let MAX=$HOW_MANY
                echo new max is $MAX
        fi
        # test every second. if you don`t need so frequenlty test - increase this value
        sleep 1
    else
        echo max count is $MAX
        echo Process was finished
        let COUNTER=11
    fi
done

Which type of java exception should be used ?

Unchecked exceptions :
  • represent defects in the program (bugs) - often invalid arguments passed to a non-private method. To quote from The Java Programming Language, by Gosling, Arnold, and Holmes : "Unchecked runtime exceptions represent conditions that, generally speaking, reflect errors in your program's logic and cannot be reasonably recovered from at run time."
  • are subclasses of RuntimeException, and are usually implemented using IllegalArgumentExceptionNullPointerException, or IllegalStateException
  • a method is not obliged to establish a policy for the unchecked exceptions thrown by its implementation (and they almost always do not do so)
Checked exceptions :
  • represent invalid conditions in areas outside the immediate control of the program (invalid user input, database problems, network outages, absent files)
  • are subclasses of Exception
  • a method is obliged to establish a policy for all checked exceptions thrown by its implementation (either pass the checked exception further up the stack, or handle it somehow)
It is somewhat confusing, but note as well that RuntimeException (unchecked) is itself a subclass of Exception (checked).



JMX Sample

public class MessageHolder implements MessageHolderMBean{
public static void main(String[] args) {

}
private String message;
@Override
public void setMessage(String message) {
this.message = message;
}

@Override
public String getMessage() {
return this.message; //To change body of implemented methods use File | Settings | File Templates.
}

@Override
public void sayHello() {
System.out.println("Messsage:"+message);
}
}


public class JmxAgent {

private MBeanServer mbs = null;

public JmxAgent() {

// Get the platform MBeanServer
mbs = ManagementFactory.getPlatformMBeanServer();

// Unique identification of MBeans
MessageHolder helloBean = new MessageHolder();
ObjectName helloName = null;

try {
// Uniquely identify the MBeans and register them with the platform MBeanServer
helloName = new ObjectName("SimpleAgent:name=ManageYourProgram");
mbs.registerMBean(helloBean, helloName);
} catch(Exception e) {
e.printStackTrace();
}
}

// Utility method: so that the application continues to run
private static void waitForEnterPressed() {
try {
System.out.println("Press to continue...");
System.in.read();
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String argv[]) {
JmxAgent agent = new JmxAgent();
System.out.println("SimpleAgent is running...");
JmxAgent.waitForEnterPressed();
}
}


public interface MessageHolderMBean
{

public void setMessage(String message);

public String getMessage();

public void sayHello();
}

Friday, March 12, 2010

Some Groovy on Soapui tests :)

Write some entry in a file like below.

[serkans@serkanslnx ~] cat /home/serkans/phoneNumbersOnly.txt
9001234560
9001234561
9001234562
9001234563
9001234564
9001234565
9001234566
9001234567
9001234562
9001234568
9001234562
9001234569

Create a test step , right click on it , Select add new Step , Select Groovy Script.Enter the following lines to it.Play Run button on the window to execute it.Do some customization to run it.File path etc..



// read the file as a properties file, but it is not :)we will get only keys from it
def properties = new java.util.Properties();
properties.load( new java.io.FileInputStream("/home/serkans/phoneNumbersOnly.txt" ));
//get a random index acc. file's line size
Random r = new Random();
def randomIndex  = r.nextInt(properties.size());
            def valueFromFile = (String) properties.entrySet().toArray()[randomIndex].toString();
            valueFromFile = valueFromFile.toString().replaceAll("=","");
log.info(valueFromFile);
return valueFromFile;


After than you need to transfer this value by using another type of Steps in soapui.
Select add new Step , Select "Property Transfer" ,Select GroovyScript as Source and select result as Property to transfer on it,Select your "Test Request" as destination and select Request as Destination.And write "//par1[@*]" to the target window.
     Look at the picture for better understanding.That is why i prefer to watch rather than reading generally:)

It will provide you Random values from file.You can use in your load tests.Enjoy!


Visit soapui page for more.

How to get SystemInfo in HP servers

[root@hpserver ~]# hpasmcli
HP management CLI for Linux (v1.0)
Copyright 2004 Hewlett-Packard Development Group, L.P.

--------------------------------------------------------------------------
NOTE: Some hpasmcli commands may not be supported on all Proliant servers.
Type 'help' to get a list of all top level commands.
--------------------------------------------------------------------------
hpasmcli> show server
System : ProLiant DL380 G5
Serial No. : CZC82758BX
ROM version : P56 01/24/2008
iLo present : Yes
Embedded NICs : 2
NIC1 MAC: 00:1X:29:e8:2c:9a
NIC2 MAC: 00:1X:29:e8:2c:98

Processor: 0
Name : Intel Xeon
Stepping : 6
Speed : 3000 MHz
Bus : 1333 MHz
Core : 4
Thread : 4
Socket : 1
Level2 Cache : 12288 KBytes
Status : Ok

Processor: 1
Name : Intel Xeon
Stepping : 6
Speed : 3000 MHz
Bus : 1333 MHz
Core : 4
Thread : 4
Socket : 2
Level2 Cache : 12288 KBytes
Status : Ok

Processor total : 2

Memory installed : 8192 MBytes
ECC supported : Yes
hpasmcli> exit
[root@hpserver ~]#