What is Null interface or Marker Interface in Java?
Marker Interfaces are those which doesn't contain any methods, but which got some purpose or capability.
It gives a message to the java compiler that it can add some special behaviour towards the class which implementing it.
Some of the Marker Interfaces are:
- java.lang.Cloneable
- java.io.Serializable
- java.util.EventListener
Let's take an example:
1) java.io.Serializable
java.io.Serializable is a marker interface, it doesn't contain any method declarations.
When a java class is to be serialized , i.e when we want to store the state of an object or pass through the network, we should intimate the java compiler in some way that there is a possibility of serializing this java class.
The java class which needs to be serialized has to implement the java.io.Serializable marker interface and by doing this we are informing the java compiler to add that capability.
2) java.lang.Cloneable
All classes that implement the Cloneable interface can be cloned (i.e., the clone() method can be called on them).
The Java compiler makes sure that if the clone() method has been called on that class which implements Cloneable Interface and also the class is implementing the Cloneable interface.
For example, consider the following call to the clone() method on an object cloneableClass:
CloneableClass cloneableClass = new CloneableClass ();
CloneableClass cl = (CloneableClass )(cloneableClass.clone());
In the above, the CloneableClass should implement the interface Cloneable, if not then the compiler will give an error. This is because the clone() method may only be called by objects of type "Cloneable."
So even if, Marker Interfaces are empty one's, it holds some special purpose.
Load Testing with JMeter
Apache JMeter
is a 100% pure Java desktop application which is used for load/traffic testing of Web Applications.
- JMeter is mainly used for load testing. It will throw many concurrent requests at your site for an
extended period of time as you wish.While our load test is executing, we have the opportunity to monitor our entire server stack and see what happens over time as your
application handles the load.
- Initially JMeter needs to be
configured to sit between the browser and the target server and then it records all the HTTP requests sent
by the browser to the server. If the target GUI accepts only HTTPS
requests, then at this phase the browser should send HTTP requests
(and Not HTTPS) to the JMeter, JMeter records those requests and
encrypt and send those to the server. Reverse thing happens
for HTTPS response. JMeter receives the responses from the
server, decrypts those records and sends the HTTP responses back
to the browser. The logical entity that is responsible for this
HTTP message recording is called Http Proxy manager.
- Once the recording is done, JMeter
can be configured to start a large number of simultaneous threads. Each thread represents one user sending/receiving the same set of
requests/responses recorded. Now onwards, it’s
between the JMeter and the server; browser is no longer used. The
component responsible for this is called thread group.
Now, To Configure JMeter follow the bellow steps.
- Download Jmeter from Here
- Go to JMETER_HOME/bin and start JMeter with jmeter.bat on windows. New window will open once you run jmeter.bat file
- Select "Test Plan" on the tree.
- Enter the details in User Defined Variables if you wish. It's not mandatory.
- Right click on the "Test Plan" and add a new thread group: Add > Threads (Users) >Thread Group.
- Select the Thread Group.
- Right click on Add -> Config Element -> HTTP Request Defaults.
- In new HTTP Request Defaults element: Server name or IP - Enter “localhost” (if you are testing it on your local machine otherwise enter relevant URL or IP address).
- Path – leave blank.
- Right click on the "Thread Group" and add a recording controller: Add > Logic Controller > Recording Controller.
- Next, select WorkBench.
- Right click on WorkBench and add the Http proxy: Add -> Non-Test Elements -> HTTP Proxy Server.
- On HTTP Proxy Server, Under Global Settings section entered port number (e.g:9090)
- On HTTP Proxy Server, Select the target Controller (created in above point number 11).
- On HTTP Proxy Server, click the “Add” button in “URL Patterns to Include”. This will create a blank entry.
- Enter ".*\.html"
- On HTTP Proxy Server, click the “Add suggested Excludes” button in “URL Patterns to Exclude”.
- Right click on "HTTP Proxy Server" and add a listener: Add -> Listener -> View Results Tree.
Now, Configure your browser to use the JMeter HTTP Proxy.
- In Firefox :
- Click on Tools > Options > Select Advanced > Select Network Tab > Click on Settings.
- Select Radio Button "Manual Proxy Configuration".
- Add Http Proxy: localhost and Port (Entered the same port number as entered in above point number 14)
- Checked check box of "Use this proxy server for all protocols".
- Press Ok.
- In Chrome:
- Click on Settings.
- Type Change proxy settings in search box.
- Click on Change proxy settings button.It will open new window of Internet Properties.
- Click on LAN settings.
- Checked the check box of "Use a proxy server for your LAN".
- Add Address: localhost and Port (Entered the same port number as entered in above point number 14)
- Click on Advanced button and Checked check box of "Use the same proxy server for all protocols".
- Click Ok.
- In IE :
- Click on Tools > Internet Options > Select Connections.
- Click on LAN settings.
- Checked the check box of "Use a proxy server for your LAN".
- Add Address: localhost and Port (Entered the same port number as entered in above point number 14)
- Click on Advanced button and Checked check box of "Use the same proxy server for all protocols".
- Click Ok.
Record Your Test Plan:
- Return to HTTP Proxy Server, and click the "Start" button at the bottom
- In your browser, In the Address bar enter "localhost:8080" (localhost: web server port number) and hit the enter key.
- Click on a few links of your application pages.
- Return to HTTP Proxy Server, and click the "Stop" button at the bottom.
Now,Expand the thread group and there should be several samplers.
Run the Test plan with JMeter:
At this point, we are ready to run our test plan. You can run the test plan with below two ways:
- Run --> Start
- Ctrl + R
While the test plan is running, in the upper right-hand corner, there should be a green square. When the test is done, the box should be grey.
Create a Scheduler in Liferay
An easy way to generate your .xsd file from .xml is with trang command line tool.
Below are the steps to generate .xsd file from .xml file.
- Download tarng.jar file and save it at your local drive.
- Generate .xsd file using below command
- java -jar <<your local machine path of trang.jar>>trang.jar addToCart.xml addToCart.xsd
E.g suppose your .xml file is as below then It will generate .xsd
addToCart.xml
<?xml version="1.0" encoding="UTF-8"?>
<addToCart>
<cartItem>
<cart_item_id><![CDATA[156]]></cart_item_id>
<cart_id><![CDATA[9]]></cart_id>
<nid><![CDATA[167]]></nid>
<qty><![CDATA[1]]></qty>
<title><![CDATA[Born To Die (Album)]]></title>
<price><![CDATA[99]]></price>
<discountedPrice><![CDATA[89.1]]></discountedPrice>
</cartItem>
</addToCart>
addToCart.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="addToCart">
<xs:complexType>
<xs:sequence>
<xs:element ref="cartItem"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="cartItem">
<xs:complexType>
<xs:sequence>
<xs:element ref="cart_item_id"/>
<xs:element ref="cart_id"/>
<xs:element ref="nid"/>
<xs:element ref="qty"/>
<xs:element ref="title"/>
<xs:element ref="price"/>
<xs:element ref="discountedPrice"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="cart_item_id" type="xs:integer"/>
<xs:element name="cart_id" type="xs:integer"/>
<xs:element name="nid" type="xs:integer"/>
<xs:element name="qty" type="xs:integer"/>
<xs:element name="title" type="xs:string"/>
<xs:element name="price" type="xs:integer"/>
<xs:element name="discountedPrice" type="xs:decimal"/>
</xs:schema>