How to Run QUnit within Maven process

Introduction

TBD

How to Setup QUnit Testing Framework in Maven

TBD

Testcase Guideline

QUnit (1.x)

  • Choose QUnit.test() and QUnit.asyncTest() wisely
  • Use QUnit.module() to group test cases,
  • the module name should follow Java package naming convention, namespace.classname, e.g. info.test.api.core.ChartAppTest
  • namespace is mandatory, which contains the project name and test scope, e.g. chart.test
  • classname is mandatory, which contains the package path down to the test module, which usually ends up with Test, e.g. api.core.ChartAppTest
  • Recover testing page inside teardown()
  • One testing file (.js) contains one module at most, and the classname of module should be same as testing file. e.g. TooltipTest.js file contains test module info.test.api.core.TooltipTest
  • Each QUnit test closure has a name as description, which starts with testXXXX, e.g. testXYBindingConvertion. The test name should not contain “.” within it.

Phantomjs (1.9.7):

  • Don’t use innerHTML property of SVGHTMLElement
  • Don’t use Function.prototype.bind. The bind function is a recent addition to ECMA-262, 5th edition; as such it may not be present in all browsers. Add below Polyfill to enable bind keyword.
    Polyfill for bind
/*
* add Polyfill for Function.prototype.bind. https://github.com/cujojs/poly
* The bind function is a recent addition to ECMA-262, 5th edition; as such it may not be present in all browsers.
* e.g phantomjs 1.9.7 doesn't support bind keyword.
*/
var isFunction = function (o) {
    return typeof o == 'function';
};
var bind,
slice = [].slice,
proto = Function.prototype,
featureMap;
featureMap = {
    'function-bind' : 'bind'
};

function has(feature) {
    var prop = featureMap[feature];
    return isFunction(proto[prop]);
}
// check for missing features
if (!has('function-bind')) {
    // adapted from Mozilla Developer Network example at
    // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
    bind = function bind(obj) {
        var args = slice.call(arguments, 1),
        self = this,
        nop = function () {},
        bound = function () {
            return self.apply(this instanceof nop ? this : (obj || {}), args.concat(slice.call(arguments)));
        };
        nop.prototype = this.prototype || {}; // Firefox cries sometimes if prototype is undefined
        bound.prototype = new nop();
        return bound;
    };
    proto.bind = bind;
}

Sample Project

Download the sample project, and play it with maven.

Reference

QUnit
Function.prototype.bind() Polyfill

Adding a Linux Slave node to Jenkins

This is a step-by-step instruction to add a Linux slave node to Jenkins.

Setup

  • Get a new server that runs Linux
  • Set up a Jenkins user (you don’t necessarily need Jenkins itself installed, but you need a dedicated user), with a home folder and proper permissions. Ideally, the user is called “jenkins” on both machines.
  • Put the master’s Jenkins SSH public key on the slave’s Jenkins user authorized_keys file (e.g. ~/.ssh/authorized_keys)

Adding the node to Jenkins

  1. Log into Jenkins with an administrator account
  2. On the Home page, go to “Manage Jenkins”, then “Manage Nodes”
  3. On the left, press “New Node”
  4. Enter a node name, then press “Dumb Slave”, then OK
  5. Enter “1” as the number of executors (you probably don’t want to build two devices at the same time)
  6. Enter your path to your jenkins user home in “Remote root directory” (e.g. /home/jenkins/workspace).
  7. Make sure Usage is set to “Only build jobs with label restrictions matching this node”, and Launch method is set to “Launch slave agents on Unix machines via SSH”
  8. Below the Launch method drop-down, enter the slave’s IP address in “Host”
  9. Choose the credential of jenkins user on master, otherwise create a new one as below
    1. Press “Add” to create a new credential
    2. Select “SSH Username with private key” kind, enter the remote username (in our case, “jenkins”)
    3. Input the private key directly or select option “From the Jenkins master ~/.ssh”
    4. If your key has a passphrase, press “Advanced” and type in the passphrase
    5. Press Save to close the dialog, and choose your new credential in the list
  10. Press Save again to save your node.

Your node is now setup! If connection can be made properly, you should see the slave’s statistics appearing in the “Manage Nodes” page.

FAQ

How to generate key-pare for SSH connection

Open PuTTYgen and click “Generate” button with key type “SSH-2 RSA“, download the public and private key files to local disk.

The public key must be in one line and starts with “ssh-rsa“, e.g.

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAjHnf5dRJPCIADtGBSUR5kM5xCC+3vttHjsMekIzmKt0pdOf2RrI5zLP00OLcRyis2uYX/bqR4pwJH13M/5zPPyKFHWoxhH3pLDlP6IkYvT3U4H+00tN5Y6aSt8H7ae1q0tB6VhqWPvv+SS1L9eY7as9if3dJw0ZkrWYVBX5IlGtWZH0Uu3qsp1p3k+l600CghOVvGlYMAgzdewMPJaRiiiC05+TUZYEPj1QnFLiIZdnQUqx8rwUj8dMUAPjzFZZHFhEiPJjX5AC885n/WBRW/dIhlurzZvsUUoKWB5KYgi1JxNOz4qOD8IriXOwOwiYAedsv8rghfbb1VqPIC3PICQ== rsa-key-20150917

The private key is stored in Jenkins system as a credential object with below,

  • Kind – SSH Username with private key
  • Scope – System (Jenkins and nodes only)
  • Username – jenkins
  • Description – <be specific>
  • Private key – Enter directly or From a file or From ~/.ssh

How to set up Jenkins user

Create a new user named as “jenkins” if it’s not existed on Linux node

Use command “useradd” or “adduser” in Linux and other Unix-like operating systems, and set a non-empty password to unlock the user

useradd jenkins
passwd jenkins
Changing password for user jenkins.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

Set proper permissions to jenkins user home directory and .ssh directory

$mkdir ~/.ssh
$chmod 700 ~/.ssh
$touch ~/.ssh/authorized_keys
$chmod 644 ~/.ssh/authorized_keys
$chown jenkins:jenkins ~/.ssh -R

How to trouble shoot when it still goes wrong

Enable the debug level log in file /etc/ssh/sshd_config

LogLevel DEBUG3

Check the log from /var/log/auth.log or /var/log/secure

How To Fix “Server refused our key” Error in CentOS 6

Refer to link, try below command

restorecon -R -v /home/jenkins/.ssh

Maven Project Guide

Introduction

This wiki page introduce a standard way to setup JavaScript-base maven project.

Folder Structure

A simple JavaScript-base project should has below folder structure, which is similar to Java-base project (see link):

High Level Folder
project
|   pom.xml
|  
+---src
|   +---assembly
|   +---main
|   |   +---config
|   |   +---js
|   |   \---resources
|   |                  
|   \---test
|       +---js
|       \---resources
|              
\---target
    |   artifact.zip
    |  
    +---bin
    |   +---build
    |   \---resources
    |              
    +---libs
    |      
    \---tp
  • pom.xml – mandatory – project description file
  • src – mandatory – source code folder
  • src/assembly – optional – assembly descriptor for project
  • src/main – mandatory – main source code
  • src/main/config – optional – build configuration file, e.g. build.js for requirejs
  • src/main/js – mandatory – JavaScript source code
  • src/main/resources – mandatory – project resources files, e.g. langs, css, image etc.
  • src/test – optional – testing
  • src/test/js – optional – test source code
  • src/test/resources – optional – test resources, e.g. benchmark
  • target – optional – general by maven build, contains the final artifact file
  • target/bin – optional – internal output files
  • target/bin/build – optional – internal output files generated by config script
  • target/bin/resources – optional – processed resources files
  • target/libs – optional – external library files, e.g. jQuery, d3 and etc.
  • target/tp – optional – third-party tools, e.g. nodejs.exe

 

A real JavaScript-base project looks like below:

JavaScript-base Project Structure
project
|   build.xml
|   pom.xml
|  
+---src
|   +---assembly
|   |       src_aio.xml
|   |      
|   +---main
|   |   +---config
|   |   |   |   build.js
|   |   |   |   export.js
|   |   |          
|   |   +---js
|   |   |   \---sap
|   |   |       \---viz
|   |   |           |   geo.js
|   |   |                          
|   |   \---resources
|   |       |   version.txt
|   |       |  
|   |       +---images
|   |       |   |   cluster.png
|   |       |   |  
|   |       |   \---map
|   |       |           logo-med.png
|   |       |          
|   |       +---langs
|   |       |       language_dev.properties
|   |       |       language_dev.properties.xliff
|   |       |       language_en.properties
|   |       |       language_en.properties.xliff
|   |       |      
|   |       +---styles
|   |       |       shadow.svg
|   |       |      
|   |       \---templates
|   |           |      
|   |           +---flashy
|   |           |       template.js
|   |           |      
|   |           \---standard
|   |                   template.js
|   |                  
|   \---test
|       +---js
|       |       placeholder.txt
|       |      
|       \---resources
|               placeholder.txt
|              
\---target
    |   sap.viz.geo-5.0.0-SNAPSHOT-standalone-aio.zip
    |  
    +---bin
    |   |   sap.viz.geo-mini.js
    |   |   sap.viz.geo.js
    |   |  
    |   +---build
    |   |       sap.geomap.bundleloader.js
    |   |       sap.geomap.modules.js
    |   |      
    |   \---resources
    |       |   version.txt
    |       |  
    |       \---langs
    |               language_dev.js
    |               language_dev.properties
    |               language_en.js
    |               language_en.properties
    |              
    +---libs
    |   \---BIFramework
    |       \---sap
    |           \---bi
    |               \---framework
    |                   +---bootstrap
    |                   |       Bootstrap.js
    |                   |      
    |                   \---kernel
    |                           DIKernel.js
    |                          
    |      
    \---tp
        \---nodejs
                LICENSE
                node.exe

Maven Build

Maven build is  defined by project pom file, a complete guide is here.

Maven Principle

  1. Do Not put any third-party source code under src folder
  2. Internal output binaries Must be generated under target/bin folder
  3. Do Not refer to files beyond project scope (src or target)
  4. Do Not contain any space in folder or file name

Simulate File Drop event in Selenium

Testing Scenario

User drag a file from operating system onto web browser, and trigger a upload

Get File object

Create an input element to create the File object

org.openqa.selenium.WebDriver driver;
WebElement fileInput = driver.findElement(By.id("fileinput"));
fileInput.sendKeys("");
Thread.sleep(2000);

Trigger a Drop event

Dispatch a drop event to target element
– Trigger the event by dispatchEvent, jQuery.trigger is not working
– MouseEvent is not working, because property dataTransfer is protected model.

driver.executeScript("var file = document.getElementById('fileinput').files[0]; "
+ "var dropEvent = new Event('drop');"
+ "dropEvent.dataTransfer = {files : [file]};"
+ "document.getElementById('filedrag').dispatchEvent(dropEvent)");
Thread.sleep(3000);

Reference

How to Fix the side-by-side error – 8.0.50727.6195

Sometimes you app may crash and find one error in application event log, e.g.

图像

It turns out that you don’t have specific version “msvcr80d.dll” file on “c:\windows\winsxs” dir. It’s usually caused by Visual Studio 2005 patch update missing. Normally you only find the 8.0.50727.762 version (“Visual C++ 2005 Service Pack 1 Redistributable Package“), which is outdated. Since the DLLs loaded by app were compiled against 6195, installing the update solved the problem. You have to install the “Microsoft Visual C++ 2005 Service Pack 1 Redistributable Package MFC Security Update”, which deploys version 8.0.50727.6195 of the VC++ assemblies. This update was hard to find at the Microsoft servers, so here’s the link: http://www.microsoft.com/download/en/details.aspx?id=26347. While in this case, the missing module is Debug version, so you have to install another update which contains debug CRT libs, here is the link http://www.microsoft.com/en-us/download/details.aspx?id=26401. Please be noticed that, the debug crt libs go with the Visual Studio 2005 Service Pack 1 MFC Security update.

Hello wordpress!

随着Live Space的终结,我也搬家到这里了,迁移时才发现自己写了几十篇日志了,自己还以为几篇而以。

wordpress的功能还不错,可惜国内访问速度太慢,只能在公司访问。另外对于博客的访问权限配置要收费的。。。默认只能添加35个人,或者选择完全公开。

———————————————————————————————–
Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!

CPU降温记

2006年毕业后和大浪一起买的电脑,久经风雨,一路走来已经换的七七八八了,09年底终于换到了双核的CPU,AMD5400+,可惜今年夏天一到,原装的风扇已经撑不住了。跑了一下推荐的《Dragon Age: Origins》游戏。CPU在满载下不用一个小时就达到90度,电脑因过热关机,即便是裸机也不成。 

看来散热器要换了,但不知道能有多少效果。于是查了一下资料,原装的CPU风扇是铝挤的,散热效果差,并且不利于在机箱内形成风道。在室温25度下,CPU空闲时61度,满载90+度(1小时后)。于是买了一个热管+风冷的超频三红海标准版HP-928,是2009年中关村的推荐产品,百元以下,价格实惠量又足。回家费了好大劲才换上,不拆主板直接安装这么大个的风扇确实困难。激动人心的时候到了,经测试CPU空闲时51度,满载62+度(1小时后)。居然差这么多,CPU降温近30度,摸着温温的散热片,心想CPU可以增寿好几年了。

另附热管散热原理,点我!

另外,《Dragon Age: Origins》推荐玩一下,尤其是喜欢DnD的,游戏画面和电影差不多,至少比《雷锋》做的好多了。

 

《阿凡达》归来

阿凡达》在上海的票真是卖得火热,不光是和平影都3D IMAX 票被炒到天价,连普通3D的票也有黄牛问津。我们周六(1月9日)在陆家嘴星美影院排队买票,本来想买周末晚场的半价票,只要75元。可惜都卖光了,只好买了下周一的票,晚8:50的普通3D(工作日还提价,半价的也要90元),就不奢望IMAX了。。。

周一在正大广场吃过晚饭,直奔8楼星美影院。捧着爆米花,换上眼镜就进场了。电影167分钟,从头到尾都引人入胜,竟然感觉不到这是一个长达3小时的电影,结束时还大呼过瘾。导演不愧是十年磨一剑,票房有赶超《Titanic》的趋势。

11:40分电影结束,楼下有798路公交直接回家,末班是11:43分。站在8楼,我考虑还是打车吧,赶不上的。老婆赶忙催我,“快快快,来得及的”。于是我们飞奔向电梯,可惜差了一步,眼看电梯门关上了。于是我们等另一部,出了电梯,冲出大楼,却看到798离去的背景。老婆指着出租车说,“快上,追”。于是我们上出租,绕近路到第一八佰伴拦截。下了出租车,看着公交站台空荡荡的,严重怀疑错过了。但不一会,798便慢悠悠的出现在了拐角,终于还是赶上了。。。

老婆二三事

  • 手机充值

我一直学习在淘宝上给手机充值,方便还能省几毛钱。也建议小雪也用淘宝,反正信用卡也办了。一天她手机没钱了,恰巧我比较忙,没有时间帮她充值,于是叫她自己充。晚上回家时,她兴高采烈地跟我说,她在淘宝上给自己手机充好钱了。我于是大大的赞扬了她一番。但她又问:
小雪:“为什么外面的50元电话卡可以充50元,淘宝上50元,只能充49元?”
我:“淘宝上也是充50元啊”
小雪:“不是啊,最多充值49.7元,我还选了一个最优惠的呢^_^”
我:“你看!这不是淘宝主页吗?这里就可以直接充值啊,你选的哪个?”
小雪:“第一个啊,可以充49.7,只差3毛钱”
我:“。。。。。。”

  • 找手机

一天下班,我打电话给她:
我:“下班了吗?什么时候回家?”
小雪:“太好了,原来手机在包包里,我不用回公司啦!还好你打电话过来,我现在马上回家!”
我:“。。。。。。”

  • QQ表情

对于老婆种种囧事,我常常在QQ上发这样的表情

但一直遭到她的反对,“你怎么老发这个表情啊,多难看!”
一次我刚刚发完,她居然利用工作之便,回了我一个山寨版的
唉,谁让她是学设计的呢。。。

Vista系统中魔兽世界声音卡的问题

在Vista系统下运行魔兽世界,会遇到声音卡的问题,并且在进入魔兽世界后,再运行其它音频软件,比如播放歌曲等,都会非常卡,无论怎么样更新声卡驱动都不行。
后来在官方论坛找到一个蓝帖:http://forums.worldofwarcraft.com/thread.html?topicId=3773503204&sid=1
内容大致如下:
Running World of Warcraft on Windows XP SP2 mode is not supported and will make
your sound choppy. Please undo the Compatibility options and have it run
natively.

魔兽世界不支持Vista下面的SP2兼容模式,会造成声音卡,请直接运行魔兽世界。

在其它地方也可以看到很多类似的问题,有的人称用特殊的声卡可以解决,但并未尝试。
http://forums.worldofwarcraft.com/thread.html?topicId=71853963&sid=1
http://forums.wow-europe.com/thread.html?topicId=612162017&sid=1

不在SP2兼容模式运行魔兽世界会使游戏画面帧数下降5到10帧,算是视频换音频吧^_^
请遇到类似的朋友不需要再反复更新声卡驱动了,经我试验,关闭Windows XP SP2兼容模式后,游戏声音一切正常。