My Note on Solutions.

Wednesday, September 24, 2014

Node.js tips and modules

Several useful modules and tips for Node.js beginners.

  • Nodemon, monitor the source file change and reload it for you automatically.

typically, we have to stop the node process and restart it when we changed the code, this happened a lot during dev phase. nodemon is the tool to solve this pain.  remember to install it as a global module. (try upgrade node to latest version if installation failed)

image

  • sleep module. sometimes you want to simulate some CPU intensive operation. or to drain the V8 thread pool, you can try this module

without sleep, this simple code can sever 100 req/s at least. since no pressure on event loop and thraed pool.

image

by ab testing with 1000 req and 1000 concurrent connections. and Node.js use little CPU.

image 

if we put sleep for each response, it will be super slow. maybe 1request every 2 seconds.

image

  • express-generator , once you install this global module, you can call the express utility to generate the project layout. like the JADE views, styles, even the stylus support.
    image

image

  • jshint , the code quality check tools

image

Sunday, September 21, 2014

Chrome Develop Tools Tips -2

  • using monitorEvents like the Spy++ using in old days to monitor event triggered on an element

image

  • by pressing CTL+F, you can use element/css/xpath selector to select the right element.

image

image

  • in the timeline of network tab, you can sort by the latency that find which site’s DNS sucks (latency)

image

image

  • besides javascript breaks, you can setup DOM breaks.

image

wheneven this is one change, it will break and stop

image

Chrome Developer Tools Tips - 1

I've been using the Chrome developer tools always, just realized several tips.

  • Console.dir will list all the attributes or methods of an object.

image

  • we can use console.group to group logs.

image

  • $ $$ and $x selector, (return 1st object, colelction and by xpath), an example running on google.com homepage.

image

  • Using inspect method to highlight the dom element get selected

image

Thursday, May 1, 2014

Sublime Text Tips, Emmet, Proxy

If you want to install a package through the console and you are behind the firewall. you can run the code in console 1st to setup the proxy.

urllib.request.ProxyHandler({"http":"http://[proxy_user]:[proxy_password]@[proxy_IP]:[proxy_port]"} )

image


there is another plugin called emmet, which is a must have tool for web developers.
install it,
image
in your html page, just type html then tab, you will see the boilerplate code,
image


in the body, If you type .container>ul>li.content*5>a[href='#']{item $}    
image

to show a route layout by typing “#content>h1.header>^panel.body>^footer”
image


if you want to put some contens in the body, type “lorem”

image



then tab



image

Friday, April 25, 2014

How To: Test Activemq 5.9.1 Master/Slave by replicatedLevelDB/Zookeeper

Start from 5.9, Activemq comes with another HA option called ReplicatedLevelDB. I would recommend start from 5.9.1 at least, and I found a lot bugs in the 5.9.
  basic idea, Zookeeper as the central coordination point, every broker talked to the Zk , ZK wills tell the member information like who is the master. slave talks to master node to fetch the incremental change when it come online.
 
for the configuration, each member in a cluster share the same broker name, zookeepeer address, and zkPass.

image

and transportconnector is transparent to the underlining persistence layer.

image

when you startup the broker, for the 1st one, since we setup the replica to 2,that means we have to start at least 2 brokers to meet the quota requirement.
 image

after 2 broker ready, you can see it’s a slave node,
image

for the 1st ndoe, which is the master node, will turn on the transportconnector that is openwire here,
image

3rd one will be a slave node too.
image

Thursday, April 24, 2014

How To: test Activemq using Maven plugins

ActiveMQ has two useful Maven plugins which enable you to test different Activemq deployment layout and Performace (Producer/Consumer) quickly. the plugins have been renamed since 5.7, and this demo is based on latest version 5.9.

Demo: Setup one standard broker quickly.

Create one maven eclipse project, and add the plugin dependency called activemq-maven-plugin to the POM file.
image

Now the pom.xml looks like this

image

for this plugin , we will add configuration later on this plugin, like the Activem.xml config, etc.
now by default, we can run the plugin on the command

image

then A simple queue broker is there, and by default using the openwire transport and memoryPersistenceAdapter.

image

TO Change the configuration, we can customize the plugin.
we setup the persistent=true and use 8888 as the openwire port.
image

Run Again,
image

if we want to change it to levelDB or more customized setting,
image

 

For the producer, you can setup another plugin, here I setup two profile, one for producer and another one is for consumer

image

the for producer, you can add different settings by passed –D to the command,
image

and consumer,
image

to start another consumer , change the prefix , otherwise, they want get any message, since they use the same consumerid

image

after done, you should see some test results, like

image

Tuesday, March 25, 2014

SoapUI, Groovy Script tutorial

Groovy is built on JVM, so does the SoapUI, it’s no surprise that SoapUI offers the Groovy script support by default. Let’s do a simple test, basically send out a Http request with dynamic parameters, and parse the result using the regular expression capability of Groovy and IO capablity to save the result back to a file. for the parameter we can use the groorvy to poll a file and return some randomized keywords.

so the keywords file looks like
image

we create one project with one test suite, then under the suite, we can add test case, and for the test step, let’s add first step called GetKeyword as a groovy script.


image

then we put some script here, which will assign a keyword property to the context randomly.
image

then we can access this keyword using context.keyword in next step, now, let’s create a http request to bing.com

image

Click extract params,now if we run this test

image

the query keyword is hardcoded, we can replace it with a groovy expression

image

then add the 3rd step, that we read the response in step 2 and save it to a file

image

if we run the test case, you will see file named keyword.txt with the http response from bing.com search

also you can just copy and save the following xml as a project file, you open in in SoapUI

<?xml version="1.0" encoding="UTF-8"?>
<con:soapui-project activeEnvironment="Default" name="tst" soapui-version="4.6.4" xmlns:con="http://eviware.com/soapui/config"><con:settings/><con:testSuite name="testgroovy"><con:settings/><con:runType>SEQUENTIAL</con:runType><con:testCase failOnError="true" failTestCaseOnErrors="true" keepSession="false" maxResults="0" name="TestCase 1" searchProperties="true" id="cdd185b8-b6ae-4455-9713-ec70b5404569"><con:settings/><con:testStep type="groovy" name="GetKeyword"><con:settings/><con:config><script>def file=new File("c:\\a.txt")
def lines=file.readLines();
def randomindex=new Random()
def keyword=lines[randomindex.nextInt(lines.size())];
context.keyword=keyword
log.info(keyword)</script></con:config></con:testStep><con:testStep type="httprequest" name="Req2Bing"><con:settings/><con:config method="GET" xsi:type="con:HttpRequest" name="Req2Bing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.WsdlRequest@request-headers">&lt;xml-fragment/></con:setting></con:settings><con:endpoint>http://www.bing.com/search</con:endpoint><con:request/><con:credentials><con:authType>Global HTTP Settings</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:parameters><con:parameter><con:name>q</con:name><con:value>${=context.keyword}</con:value><con:style>QUERY</con:style><con:default>androidyou</con:default><con:path xsi:nil="true"/><con:description xsi:nil="true"/></con:parameter></con:parameters></con:config></con:testStep><con:testStep type="groovy" name="SaveitToFile"><con:settings/><con:config><script>def resp=testRunner.getTestCase().getTestStepByName("Req2Bing").httpRequest.response
def raw=resp.getContentAsString()
//save it fo file
def resultFile=new File("c:\\" + context.keyword + "t.txt")
resultFile.write(raw);</script></con:config></con:testStep><con:properties/></con:testCase><con:properties/></con:testSuite><con:properties/><con:wssContainer/></con:soapui-project>

 
Locations of visitors to this page