Git flow for working on svn branch

July 25, 2011 by · Comments Off on Git flow for working on svn branch
Filed under: git 

The Problem: you want to play on git code branches on svn server. Here’s the simple flow.

1. Specify the layout when running git svn clone:

Specify the trunk, branch and tags by -T,-b,-t, such as: -T dev -b branches -t tags

2. To fetch all updates of all svn server branches:

git svn fetch

When you run git svn fetch, all branches will be updated, and new branches on the remote will be added. git svn fetch fetches the updates with out modifying the local working files (while git svn rebase would).

3. To show all branches include server branches:

git branch -r

4. To switch to work on a server branch: server-branch-v2.8

git checkout -b local-v2.8 server-branch-v2.8 then working on the local-2.8 branch, and commit, dcommit, your changes would be dcommitted to the server branch.

Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Facebook charged from my credit card without my awareness

July 24, 2011 by · 13 Comments
Filed under: tech watch 

 

I’m trying to install a word press plugin, and clicked this link to create a facebook app: Facebook Connect Setup.

Facebook says you must activate the application by mobile number or credit card on the setup page.

After I input my credit card number and confirmed.  I received a notification of 1.0.1 dollar transaction fee online for my credit card.

But facebook mentioned nothing about activation fee or any other charging terms on the setup page. I tried find a page to complain on facebook.com for about half an hour, but find nothing.

I’m browsing facebook by a proxy, not sure whether it is related to the proxy by not displaying any pricing terms on the setup page.

Anyway, it is really frustrating being charged without authorization.  I’m doubting is it things done by facebook as a company praised to be better than google to charge its users secretly?

Could anyone help me to contact their customer service?

 

Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

How to enable remote JMX support on tomcat

July 21, 2011 by · Comments Off on How to enable remote JMX support on tomcat
Filed under: java 

We need to monitor tomcat by jconsole and visualvm for check memory/thread/object usage of tomcat when problem occur. So I tried to enable JMX support on tomcat by modify the catalina.sh by some suggest online (in one line, for windows, “export” should be replaced by “set”):

export JAVA_OPTS="-Dcom.sun.management.jmxremote.port=8086
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false"

And connect successfully to tomcat by jconsole on local machine. But failed to connect tomcat on remote machine.

In fact, to enable remote access of JMX, you need to specify the server hostname such as:

export JAVA_OPTS="-Dcom.sun.management.jmxremote.port=8086
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Djava.rmi.server.hostname=192.168.32.12"

Note: the hostname could not be 0.0.0.0 to represents any server name. For windows, should use “set” instead of “export”. 

Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

3 steps to dynamically compile, instantiate and run a Java class

July 20, 2011 by · 2 Comments
Filed under: java 

The background:  sometimes we need to compile dynamic source code, and run the code.  Some common situation includes on a program contest evaluation system, on a dynamic business logic control,  on evaluation of dynamic math expression, or even on evaluation of dynamic expression on test case.

Here’s 3 steps to implement compilation, instantiation and running of dynamic java source code.  It is the hard way,  the most original and elastic way; cause you can add any logic in the generation of your dynamic source code.

1. Construct an in-memory java source file from your dynamic code.

You need to override SimpleJavaFileObject, and take a string content as and In memory java source file.

2.Compile your files by JavaCompiler

You need to compile by JavaCompiler which could be got by ToolProvider.getSystemJavaCompiler(). Then get a task of JavaCompiler.CompilationTask. And call the task to execute compilation.

3.Load your class by URLClassLoader

Load your class by URLClassLoader from classes output folder, then instantiate a instance from the class, and finally call method of the class from the instance by reflection.

Here’s a complete working code (tested on JDK 1.6):

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.Locale;

import javax.tools.Diagnostic;
import javax.tools.DiagnosticListener;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;

/**
 * Dynamic java class compiler and executer  <br>
 * Demonstrate how to compile dynamic java source code, <br>
 * instantiate instance of the class, and finally call method of the class <br>
 *
 * http://www.beyondlinux.com
 *
 * @author david 2011/07
 *
 */
public class DynamicCompiler
{
    /** where shall the compiled class be saved to (should exist already) */
    private static String classOutputFolder = "/classes/demo";

    public static class MyDiagnosticListener implements DiagnosticListener<JavaFileObject>
    {
        public void report(Diagnostic<? extends JavaFileObject> diagnostic)
        {

            System.out.println("Line Number->" + diagnostic.getLineNumber());
            System.out.println("code->" + diagnostic.getCode());
            System.out.println("Message->"
                               + diagnostic.getMessage(Locale.ENGLISH));
            System.out.println("Source->" + diagnostic.getSource());
            System.out.println(" ");
        }
    }

    /** java File Object represents an in-memory java source file <br>
     * so there is no need to put the source file on hard disk  **/
    public static class InMemoryJavaFileObject extends SimpleJavaFileObject
    {
        private String contents = null;

        public InMemoryJavaFileObject(String className, String contents) throws Exception
        {
            super(URI.create("string:///" + className.replace('.', '/')
                             + Kind.SOURCE.extension), Kind.SOURCE);
            this.contents = contents;
        }

        public CharSequence getCharContent(boolean ignoreEncodingErrors)
                throws IOException
        {
            return contents;
        }
    }

    /** Get a simple Java File Object ,<br>
     * It is just for demo, content of the source code is dynamic in real use case */
    private static JavaFileObject getJavaFileObject()
    {
        StringBuilder contents = new StringBuilder(
                                                   "package math;"+
                                                            "public class Calculator { "
                                                           + "  public void testAdd() { "
                                                           + "    System.out.println(200+300); "
                                                           + "  } "
                                                           + "  public static void main(String[] args) { "
                                                           + "    Calculator cal = new Calculator(); "
                                                           + "    cal.testAdd(); "
                                                           + "  } " + "} ");
        JavaFileObject so = null;
        try
        {
            so = new InMemoryJavaFileObject("math.Calculator", contents.toString());
        }
        catch (Exception exception)
        {
            exception.printStackTrace();
        }
        return so;
    }

    /** compile your files by JavaCompiler */
    public static void compile(Iterable<? extends JavaFileObject> files)
    {
        //get system compiler:
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

        // for compilation diagnostic message processing on compilation WARNING/ERROR
        MyDiagnosticListener c = new MyDiagnosticListener();
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(c,
                                                                              Locale.ENGLISH,
                                                                              null);
        //specify classes output folder
        Iterable options = Arrays.asList("-d", classOutputFolder);
        JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager,
                                                             c, options, null,
                                                             files);
        Boolean result = task.call();
        if (result == true)
        {
            System.out.println("Succeeded");
        }
    }

    /** run class from the compiled byte code file by URLClassloader */
    public static void runIt()
    {
        // Create a File object on the root of the directory
        // containing the class file
        File file = new File(classOutputFolder);

        try
        {
            // Convert File to a URL
            URL url = file.toURL(); // file:/classes/demo
            URL[] urls = new URL[] { url };

            // Create a new class loader with the directory
            ClassLoader loader = new URLClassLoader(urls);

            // Load in the class; Class.childclass should be located in
            // the directory file:/class/demo/
            Class thisClass = loader.loadClass("math.Calculator");

            Class params[] = {};
            Object paramsObj[] = {};
            Object instance = thisClass.newInstance();
            Method thisMethod = thisClass.getDeclaredMethod("testAdd", params);

            // run the testAdd() method on the instance:
            thisMethod.invoke(instance, paramsObj);
        }
        catch (MalformedURLException e)
        {
        }
        catch (ClassNotFoundException e)
        {
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception
    {
        //1.Construct an in-memory java source file from your dynamic code
        JavaFileObject file = getJavaFileObject();
        Iterable<? extends JavaFileObject> files = Arrays.asList(file);

        //2.Compile your files by JavaCompiler
        compile(files);

        //3.Load your class by URLClassLoader, then instantiate the instance, and call method by reflection
        runIt();
      }
}
Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

How to automate test cases which need to be run in a clean OS

July 11, 2011 by · 1 Comment
Filed under: automation, test 

Sometimes we need to automatically run some test cases which need to be run in an clean os. Such as application software installation benchmark. If you’d like to test performance of office installation under Microsoft Windows with different antivirus installed. The software installation is a test case, and it should be run in a clean OS.  Here’s the tools and steps. (works on Microsoft Windows XP).

4 Tools need to be prepared:

Grub4dos:  used to load dos image (modify default boot into OS in menu.lst).

Maxdos image (maxdos.img): which is extracted from max dos, and can be used to boot in to pure dos from grub4dos. Also you can use any other dos image which can boot into dos instead. (Images in vFloppy is recommended too)

Win Image: which we need to use for changing content in dos image file. We modify autoexec.bat in dos image to restore OS automatically and reboot.

Ghost: which we need to restore OS ghost image automatically.

5 Steps to automate test cases which need to be run in a clean restored OS:

1. Prepare a clean os, and make a ghost image (ghost\win.gho).

Before make the ghost image,  put your test script (such as start.script.bat) caller file to the  start-up menu in OS.  So that the script will be run automatically once upon reboot.

Make sure you windows system is in NTFS partition, and prepare a FAT32 partition, copy the ghost image win.gho to the FAT32 partition (ghost\win.gho) so that in pure dos we can read and restore the ghost image.

2. Modify c:\boot.ini to boot into grub (follow the readme of grub4dos to install grub on your system before this step).

[boot loader]
timeout=5
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect
c:\grldr=Grub

3. Edit grub boot configs to automatically boot into maxdos image

title restore by MAXDOS
find --set-root --ignore-floppies /boot/maxdos.IMG
map --mem /boot/maxdos.IMG (fd0)
map --hook
chainloader (fd0)+1
rootnoverify (fd0)

4. Maxdos boot into into DOS automatically.

5. In the dos imaged (maxdos.img), modify the autoexec.bat to restore ghost automatically. (You need first extract files from maxdos.img by Win Image, then modify the files, and put the files back to the img file):

ghost.exe -clone,mode=pload,src=c:\ghost\win.GHO:1,dst=1:1 -fx -sure -rb

Plus, if you need to run several different cases, each case need to be run in a clean environment. You can do it in your start.script.bat as the following link:

How to automate test cases need reboot: a simple script solution

Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

How to automatically install/uninstall software without human interaction

July 11, 2011 by · 1 Comment
Filed under: automation, test 

Sometimes we need to automatically install/uninstall software without human interaction, especially for system performance test. How can we make it work?

A simple and easy way is to leverage AutoIt. Auto it can be used to simulate keystrokes and mouse movements automatically. Just download it from here. Then install it.

And open an editor, SciteEditor4AutoIt3 is recommended as a bundle in AutoIt, write autoit script by examples provided by AutoIt help document. During the writing, you can use AutoIt Window Info which is installed with AutoItV3 to capture your software window information. You will need these window information in your scripts.

Here’s the script for automatically install iTunes 9.0:

; filename: install.itunes.au3,  automatic software install
run("iTunesSetup-9.0.2.25.exe")
WinWaitActive( "iTunes + QuickTime" )

; click next
ControlClick("iTunes + QuickTime", "", "[ID:6315]")
WinWaitActive( "iTunes + QuickTime" )

; accept license
ControlClick("iTunes + QuickTime", "", "[ID:6434]")
WinWaitActive( "iTunes + QuickTime" )

;; click next
ControlClick("iTunes + QuickTime", "", "[ID:6315]")
WinWaitActive( "iTunes + QuickTime" )

;;click install
ControlClick("iTunes + QuickTime", "&Install", "[ID:6348]")

;; wait the install successful UI:
While 1
	; find control (Yes button) whose Text is &Finish :
	$var = ControlGetText("iTunes + QuickTime", "", "[Text:&Finish]") 

    If $var == "&Finish" Then
		; tick not to open UI
		ControlClick("iTunes + QuickTime", "", "[ID:6414]")

		; send Alt + F to finish install
		Send("!F")

        ExitLoop
    EndIf

	Sleep(1000)
WEnd

Here’s the script for uninstall iTunes 9.0:

; automatic software install
run("iTunesSetup-9.0.2.25.exe")
WinWaitActive( "iTunes + QuickTime" )

; click remove
ControlClick("iTunes + QuickTime", "&Remove", "[ID:6484]")

; find "Yes" button until it show, and then send Alt + Y
While 1
	; find control (Yes button) whose ID is 6434 :
	$var = ControlGetText("iTunes + QuickTime", "", "[ID:6434]") 

    If $var == "&Yes" Then
		; send Alt + Y to confirm uninstall
		Send("!Y")

        ExitLoop
    EndIf

	Sleep(1000)
WEnd

; find "Finish" button until it show, and then send Alt + F
While 1
	; find control (Yes button) whose ID is 6434 :
	;$var = ControlGetText("iTunes + QuickTime", "", "[ID:6412]")
	$var = ControlGetText("iTunes + QuickTime", "", "[Text:&Finish]") 

    If $var == "&Finish" Then
		; send Alt + F to finish uninstall
		Send("!F")
		;ControlClick("iTunes + QuickTime", "&Finish", "[ID:6412]")

        ExitLoop
    EndIf

	Sleep(1000)
WEnd

sleep(500);

;WinWaitActive( "iTunes + QuickTime" ) ; commented by david, 2010/05/04
; click "No" to not reboot the os:
ControlClick("iTunes + QuickTime", "&No", "[ID:7]")

;MsgBox(4096, $count,"", 5);

The script for install Microsoft Office 2007:

; filename: install.office.au3 ,automatic software install
run("office2007\\setup.exe")

WinWaitActive( "Microsoft Office Professional 2007" )
Sleep(100)
;ControlClick("Microsoft Office Professional 2007", "", "[Text:Continue]")
Send("!c")

WinWaitActive( "Setup" )

ControlClick("Setup", "", "[Text:&No]")

WinWaitClose("Setup")

; Alt + a to accept the terms of this agreement:
Send("!a")
Sleep(100)

; click "continue" button:
Send("{ENTER}");

; Click "Install Now"
Send("!i")

Sleep(500)

;WinWaitClose( "Microsoft Office Professional 2007" )
;WinWaitActive( "Microsoft Office Professional 2007" )

While 1
	; Send Alt + C to "Close":
   Send("!c")

	; find control (Yes button) by Text :
	$text = WinExists ("Microsoft Office Professional 2007", "")

    If $text == 0 Then
	     ;; window not found
         ExitLoop
    EndIf

	Sleep(1000)
WEnd

 

The script for uninstall Microsoft Office 2007:

; automatic software uninstall
run("office2007\\setup.exe")

WinWaitActive( "Microsoft Office Professional 2007" )

; remove:
Send("!m")

; Send Enter to "continue" :
Send("{ENTER}");

; confirm the dialog of "Are you sure you want to remove Microsoft Office professional 2007?":
WinWaitActive( "Setup" )
ControlClick("Setup", "", "[Text:&Yes]")
WinWaitClose("Setup")

While 1
   ; try to Send Alt + C to "Close":
   Send("!c")
   Sleep(100)

	; find control (Yes button) by Text :
	$var = ControlGetText("Setup", "", "[Text:&No]") 

    If $var == "&No" Then
		 ;;WinWaitActive( "Setup" )
		 ControlClick("Setup", "", "[Text:&No]")
		 WinWaitClose("Setup")
         ExitLoop
    EndIf

	Sleep(500)
WEnd
Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Noticeable Hacker news I read(2011/06)

July 1, 2011 by · Comments Off on Noticeable Hacker news I read(2011/06)
Filed under: design, tech watch 

Post for startup :

Where to find a co-founder/

Why startup needs blog/

 

Post for tech:

Ultra KSM — An improvement upon Linux’s memory merging support enabling transparent full system scan at ultra speed

Hacking the system: How to land meetings with anyone you want

understanding v8

Speed up your eclipse as a super fast IDE

write your first mapreduce program in 20 minutes/

good machine learning blogs

Reflections and advice on life as a mid-stage Ph.D. student
What are your favorite Vim tricks?

http://research.microsoft.com/en-us/people/simonpj/

http://projecteuler.net/ (Programming Challenge)

 

Post for Learning , Attitude and Lifestyle:

Things ics students should do before graduating/

A new billionaires 10 rules for success/

Harvard Classics (Bookshelf)

Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

How to automate test cases need reboot: a simple script solution

July 1, 2011 by · Comments Off on How to automate test cases need reboot: a simple script solution
Filed under: automation, test 

During the first 2 years in my career as a tester, I learned that for a tester, everything should be automated if possible. 2 years later I beginning my programming life and found that automation is a must skill for programmers too. There is lots of interesting things on my testings experience, here’s one of them.

The background: Sometimes we need to run some test cases, and each case must be run in a newly booted environment. Or when case B is depended on case A which need reboot after run. And we want automation of the process. (IT software installation, Antivirus performance test, etc is some practice requirement like this).

A simple way to automate such test case is : write the test cases in scripts, define all the
test cases script file name in an array scriptlist,  then run the script files whose name
is defined in the elements of the array one by one.  We can define an index for which script
is to be running in the array.  And each time we run a script file, we save the index, lets
say idx to a file on local disk.

Assum you have 4 scripted test cases to run in order: A.pl, B.pl, C.pl, D.pl (the script
language doesn’t matter, you can choose whatever you love). and after running of each case, need a system reboot.

We can write a new script called reboot-test-manager.pl, and put it to the auto start. Then
run the script manually as a trigger for the starting of all these 4 cases. Then each one
will run and reboot, and continue to run the next one.

Here’s the 4 simple things should be contained in the reboot-test-manager.pl, I’ll
demonstrate it in perl on windows, for linux some command must the changed, you know).

1).Initialize the index(idx) value
If next-file-torun.txt exist, try to read idx value from next-file-torun.txt,  else set $idx  value to zero.

my $idx = 0;
my @scriptlist=  ("A.pl","B.pl","C.pl","D.pl");

2). Save the idx value to a local file called next-file-torun.txt
The idx value indicates the file whose name is equal to scriptlist[idx] will be run.
echo $idx >next-file-torun.txt

3). Run the file indicated by scriptlist[idx] , and then increase idx by 1

my $filetorun = $scriptlist[$idx];
system("$filetorun");
$idx=$idx+1;

4). Reboot by restart command

system("shutdown -r -t 01");

Then script A.pl will be run, then reboot, then script B.pl will be run, then reboot and C.pl
….

This method is really useful on automation lots of software installation for IT if the
software need reboot. Also useful when we need to test some software performance  on a newly booted system, especially for antivirus performance test.

Here’s a sample script for running:

# The script would be run after system reboot

my @filelist =  ("install.a.pl","install.b.pl","install.c.pl");

##
my $idfile="next-file-torun.txt";
open READIN,"< $idfile" or die "can not open file:$!";
my $id = <READIN>;
close (READIN);
print "id=$id \n";

if($id>$#filelist)
{
	print "all files has been run!\n";
	print "\x07\x07"; # ring the bell
	exit(-1);
}

# sleep some seconds to run the following scripts:
print "sleeping...\n ";
sleep(10);

my $filetorun = $filelist[$id];
print "to run file:  $filetorun \n";

$id=$id+1;
open OUT,"> $idfile" or die "can not open file:$!";
print OUT $id;
close (OUT);

system("$filetorun");  ### call the script
system("shutdown -r -t 01"); ### reboot the system
Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)