mercredi 7 décembre 2011

How to mock httpRequest with jMockit

/**
* test getMultiple param
* @param request
*/
@Test
public void testGetMultipleParams(final HttpServletRequest request) {

new NonStrictExpectations()
{
// A "local" mock field ("@Mocked" is implied when not annotated):
{
request.getParameter("feed1"); result = "http://feed1";
request.getParameter("feed2"); result = "http://feed2";
request.getParameter("feed3"); result = "http://feed3";
request.getParameter("feed4"); result = null;
}
};

ArrayList toto = RssAggregatorServlet.getMultipleParams(request, "feed");
assertThat(toto.size(),equalTo(3));

assertThat(toto.toArray(new String[0]),equalTo(new String[]{"http://feed1","http://feed2","http://feed3"}));

mercredi 30 novembre 2011

Ultimate boot cd

Donc je disais.
C'est un distro linux qui permet de faire du ghost, HDD et memory test entre autre.
On peut l'installer facilement sur une clé usb via Universal USB Installer – Easy as 1 2 3

http://www.pendrivelinux.com/universal-usb-installer-easy-as-1-2-3/

Profiling

VisualVM is a visual tool integrating several commandline JDK tools and lightweight profiling capabilities. Designed for both production and development time use, it further enhances the capability of monitoring and performance analysis for the Java SE platform

http://visualvm.java.net/

Give a further look at this tool

jeudi 17 novembre 2011

HTML5 : cap sur le stockage des données en local

Un très bon article d'exemple sur le stockage de données en html 5.

http://www.journaldunet.com/developpeur/client-web/html5-stockage-de-donnees-en-local-web-storage/

mercredi 1 juin 2011

Disable IPv6 in Ubuntu 8.04

To disable IPv6, open a shell and append the following to /etc/modprobe.d/blacklist:

# disable ipv6
blacklist ipv6

Reboot.

To verify that IPv6 is disabled, run

lsmod | grep ipv6

or

ip a | grep inet6

jeudi 27 janvier 2011

VMware ESXi SSH CLI commands

One of the biggest challenges I run into working with ESXi hosts is the lack of a real usable CLI. The remote CLI provided by VMware is clunky at best and makes administration a bit of a pain. I did some poking around and managed to find some interesting CLI commands that work for ESXi.

Most of these have no manual page but will output a help message if run by themselves. I would recommend using extreme caution and using a test host to determine the usefulness in your environment before using them on an important system. Also keep in mind that the examples that I give are not the "only" way the commands can be used.

vim-cmd vmsvc/getallvms
Lists all vm's running on hypervisor and provides vmid

vim-cmd vmsvc/power.off vmid
Powers off vmid referenced from getallvms command

vim-cmd vmsvc/power.on vmid
Powers off vmid referenced from getallvms command

vim-cmd vmsvc/power.reboot vmid
Reboots vmid referenced from getallvms command

vim-cmd vmsvc/destroy vmid
Deletes the vmdk and vmx files from disk

vim-cmd hostsvc/maintenance_mode_enter
Puts hypervisor into maintenance mode

vim-cmd hostsvc/maintenance_mode_exit
Takes hypervisor out of maintenance mode

vim-cmd solo/registervm /vmfs/vol/datastore/dir/vm.vmx
Registers vm in hypervisor inventory

vim-cmd vmsvc/unregister vmid
Unregisters vm with hypervisor

vim-cmd vmsvc/tools.install vmid
Starts vmware tools installation for VM

vim-cmd hostsvc/net/info
Provides information about hypervisor networking

chkconfig -l
Shows daemons running on hypervisor. Can also be used for configuration.

esxtop
Same as linux top for vmware

vmkerrcode -l
List of vmkernel errors

esxcfg-info
Lists a LOT of information about the esx host

esxcfg-nics -l
Lists information about NIC's. Can also be used for configuration.

esxcfg-vswitch -l
Lists information about virtual switching. Can also be used for configuration.

dcui
Provides console screen to ssh session

vsish
Vmware interactive shell

decodeSel /var/log/ipmi_sel.raw
Read System Event Log of server

vendredi 14 janvier 2011

Postgres BackUp & Restore

http://www.postgresql.org/docs/8.1/static/backup.html#BACKUP-DUMP

23.1. SQL Dump

The idea behind the SQL-dump method is to generate a text file with SQL commands that, when fed back to the server, will recreate the database in the same state as it was at the time of the dump. PostgreSQL provides the utility program pg_dump for this purpose. The basic usage of this command is:

pg_dump dbname > outfile

As you see, pg_dump writes its results to the standard output. We will see below how this can be useful.

pg_dump is a regular PostgreSQL client application (albeit a particularly clever one). This means that you can do this backup procedure from any remote host that has access to the database. But remember that pg_dump does not operate with special permissions. In particular, it must have read access to all tables that you want to back up, so in practice you almost always have to run it as a database superuser.

To specify which database server pg_dump should contact, use the command line options -h host and -p port. The default host is the local host or whatever your PGHOST environment variable specifies. Similarly, the default port is indicated by the PGPORT environment variable or, failing that, by the compiled-in default. (Conveniently, the server will normally have the same compiled-in default.)

As any other PostgreSQL client application, pg_dump will by default connect with the database user name that is equal to the current operating system user name. To override this, either specify the -U option or set the environment variable PGUSER. Remember that pg_dump connections are subject to the normal client authentication mechanisms (which are described in Chapter 20).

Dumps created by pg_dump are internally consistent, that is, updates to the database while pg_dump is running will not be in the dump. pg_dump does not block other operations on the database while it is working. (Exceptions are those operations that need to operate with an exclusive lock, such as VACUUM FULL.)

Important: When your database schema relies on OIDs (for instance as foreign keys) you must instruct pg_dump to dump the OIDs as well. To do this, use the -o command line option.

23.1.1. Restoring the dump

The text files created by pg_dump are intended to be read in by the psql program. The general command form to restore a dump is

psql dbname < infile

where infile is what you used as outfile for the pg_dump command. The database dbname will not be created by this command, you must create it yourself from template0 before executing psql (e.g., with createdb -T template0dbname). psql supports options similar to pg_dump for controlling the database server location and the user name. See psql's reference page for more information.

Not only must the target database already exist before starting to run the restore, but so must all the users who own objects in the dumped database or were granted permissions on the objects. If they do not, then the restore will fail to recreate the objects with the original ownership and/or permissions. (Sometimes this is what you want, but usually it is not.)

Once restored, it is wise to run ANALYZE on each database so the optimizer has useful statistics. An easy way to do this is to run vacuumdb -a -z to VACUUM ANALYZE all databases; this is equivalent to running VACUUM ANALYZE manually.

The ability of pg_dump and psql to write to or read from pipes makes it possible to dump a database directly from one server to another; for example:

pg_dump -h host1 dbname | psql -h host2 dbname

Important: The dumps produced by pg_dump are relative to template0. This means that any languages, procedures, etc. added to template1 will also be dumped by pg_dump. As a result, when restoring, if you are using a customized template1, you must create the empty database from template0, as in the example above.

For advice on how to load large amounts of data into PostgreSQL efficiently, refer to Section 13.4.