Dec 24, 2013

[memo] Eclipse proxy configuration

Eclipse 4.2
Window -> Preferences -> search network
Set your Host and Post for HTTP and HTTPS. Do not set SOCKS

Nov 19, 2013

[memo] Maven release:perform DO NOT deploy

As you know web application is not supposed to be uploaded maven repository. I tried to not deploy on the release. Finall I found the answer here.
It took much time.

<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<releaseProfiles>release</releaseProfiles>
<goals>package</goals>
</configuration>
</plugin>
view raw release.xml hosted with ❤ by GitHub

Nov 17, 2013

[memo] Print file names that contain word and exclude extension.

### command
find ${TARGET_DIR}/*.xml -type f | xargs grep -l ${SEARCH_WORD} | awk '{ num = split($0, array, "/"); print array[num];}' | awk '{ num = split($0, array, "."); print array[1];}'

Nov 15, 2013

Jenkins Git Plugin fails with NullPointerException

When I ran Jenkins job to build project, I got the following error message.
Started by user superman
Building in workspace /var/lib/jenkins/jobs/myproject/workspace
Checkout:workspace / /var/lib/jenkins/jobs/myproject/workspace - hudson.remoting.LocalChannel@449b369
Using strategy: Default
FATAL: null
java.lang.NullPointerException
at hudson.plugins.git.GitSCM.resolveGitTool(GitSCM.java:821)
at hudson.plugins.git.GitSCM.getGitExe(GitSCM.java:837)
at hudson.plugins.git.GitSCM.getGitExe(GitSCM.java:830)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1088)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1367)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:674)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:579)
at hudson.model.Run.execute(Run.java:1575)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:477)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:237)
view raw NPE.java hosted with ❤ by GitHub


I found the answer from here.

1. Uninstall git client plugin
2. Restart, it would be automatically executed
3. Install git plugin, not git client. Git client is installed automatically too.
4. Confirm git is available and name it "default" on Manage Jenkins > Configure System

Enjoy!

Nov 14, 2013

[memo] this parser does not support specification null version null digester

java.lang.UnsupportedOperationException: This parser does not support specification "null" version "null"
at javax.xml.parsers.SAXParserFactory.setXIncludeAware(SAXParserFactory.java:448)
at org.apache.commons.digester.Digester.getFactory(Digester.java:534)

Update your xercesImpl.jar!!! old xercesImpl.jar can not handle setXIncludeAware method.
2.9.1 helps you.

Thank you Coding in Color!!!


Oct 30, 2013

[memo] shell script percentage calculate

Just for me.

#!/bin/sh
a=2
b=3
echo "scale=1; (100 * $a / $b)" | bc
#Result is 66.6
view raw percent.sh hosted with ❤ by GitHub

Aug 15, 2013

[memo] how to concat logs that are behind specific time to one file

Here what I did.

find /my/logdir/ -newer /my/logdir/delete.log.2013-08-12-13 -type f -exec cat {} > /my/temp/delete.txt \;
view raw find.sh hosted with ❤ by GitHub

Jul 24, 2013

Continuous Delivery Using Jenkins

Let me introduce our Jenkins jobs. If Jenkins was not exist, we would suffer from HARD HARD build and deploy jobs.

First of all, we made our server list file. Because this is very often used by Jenkins deploy and restart jobs.
Add your Jenkins user key to my_name/.ssh/authorized_key on each server.
-Jenkins Server List Configure Job-
CONFIG(){
test -e $1 && cp $1 $1.old
cat > $1 <<EOF
192.28.255.111
192.28.255.112
EOF
test -e $1.old && diff $1 $1.old|cat
}
CONFIG /usr/local/repository/prd/my_product.list


Next step, we build our project and make backup too.
-Jenkins Build Job-
Build our project by running maven.
  clean release:clean release:prepare package -P prd

And make backup directory.
#This script is for jenkins build job
OLD_DIR=$(date +"%Y_%m_%d_%H_%M_%S")
REPO=/usr/local/repository/prd/my_product/
BACKUP_DIR="/usr/local/repository/prd/my_product_backup"
if [ -d "$BACKUP_DIR" ]; then
mv $BACKUP_DIR/my_product $BACKUP_DIR/$OLD_DIR/
fi
mv $REPO $BACKUP_DIR/my_product/
/usr/bin/rsync -acvz ${WORKSPACE}/target/deploy/ $REPO --delete


And run deploy job. Don't forget set post-build Actions. We set Build other projects(Jenkins Restart Job)
-Jenkins Deploy Job-
LIST=/usr/local/repository/prd/my_product.list
REPO=/usr/local/repository/prd/my_product
DEST=/usr/local/app/
sed -e "s/#.*//" -e "s/^\s*$//" $LIST | while read i; do
echo "#### deploy -> $i ####"
rsync -e 'ssh -o StrictHostKeyChecking=no' -acvz --delete --exclude="logs" $REPO my_name@$i:$DEST
done
sed -e "s/#.*//" -e "s/^\s*$//" $LIST


-Jenkins Restart Job-
LIST=/usr/local/repository/prd/my_product.list
COMMAND="sh /usr/local/app/my_product/bin/my_product_control.sh restart"
sed -e "s/#.*//" -e "s/^\s*$//" $LIST | while read i; do
echo "#### restart -> $i ####"
ssh -o 'StrictHostKeyChecking=no' -2 -n my_name@$i $COMMAND
done


Sometimes we need to revert our service. We use this job. Don't forget to set Build other projects(Jenkins Deploy Job) that it will execute Jenkins Restart Job.
-Jenkins Roll Back Job-
/usr/bin/rsync -acvz /usr/local/repository/prd/my_product_backup/my_product/ /usr/local/repository/prd/my_product/ --delete

Jul 22, 2013

[memo] jmagick 6.4.0 configure problem

I had to install jmagick 6.4.0. And I tried to install as the following.

tar xvzf /opt/jmagick-6.4.0-src.tar.gz -C /opt
chown -R root.root /opt/6.4.0
cd /opt/6.4.0
./configure --prefix=/opt/jmagick-6.4.0 --with-java-home=/opt/java/ --with-magick-home=/opt/imagemagick
make all
make install
rm /opt/jmagick
ln -s /opt/jmagick-6.4.0 /opt/jmagick
view raw jmagick.sh hosted with ❤ by GitHub


Jmagick dose not care "--with-java-home=/opt/java/". It just uses "/usr/bin/java javac javah jar".
So you need to link them to /usr/bin

#ln -s /opt/java/bin/java /usr/bin/java


[memo] svc: warning: unable to control file does not exist.

I solved this problem here.

The key is the following command.
# svscanboot &

Jul 9, 2013

[memo] How to add many nodes to Chef Server

I created my node.json file with jackson. And I need to add 100 over nodes to Chef server.
I uploaded to Chef server's tmp directory my nodes files and ran the following script.
#!/bin/bash
for i in /tmp/*
do
knife node from file $i
done
view raw noderegister.sh hosted with ❤ by GitHub


It is simple!

Jun 21, 2013

[memo] How to delete old files in Linux

find ./ -mtime +60 -name "*.log" | xargs mv --target-directory=/tmp
cd /tmp
rm *.log
# or run the following command
find ./ -mtime +60 -name "*.log" | xargs rm -f

Jun 7, 2013

maven scala java mixed project

I develop my product with Java and have test code written by Scala(Specs2). I wanted run test cases on my PC and Jenkins.
I have got some problems and solved by the following pom.xml. It works well. I hope this helps you.

Don't forget add "@RunWith(classOf[JUnitRunner])" to your xxxSpec class.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>baepiff</groupId>
<artifactId>sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.debug>true</maven.compiler.debug>
<maven.compiler.optimize>true</maven.compiler.optimize>
<maven.compiler.showDeprecations>true</maven.compiler.showDeprecations>
</properties>
<repositories>
<repository>
<id>public</id>
<name>Internal Repository</name>
<url>http://localhost/nexus/content/groups/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public</id>
<name>Internal Repository</name>
<url>localhost/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
<scm>
<connection>scm:git:git@localhost:baepiff/sample.git</connection>
<url>scm:git:git@localhost:baepiff/sample.git</url>
<developerConnection>scm:git:git@localhost:baepiff/sample.git</developerConnection>
</scm>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<encoding>${maven.compiler.encoding}</encoding>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<debug>${maven.compiler.debug}</debug>
<optimize>${maven.compiler.optimize}</optimize>
<showDeprecation>${maven.compiler.showDeprecations}</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>com.mmakowski</groupId>
<artifactId>maven-specs2-plugin</artifactId>
<version>0.4.1</version>
<executions>
<execution>
<id>verify</id>
<phase>verify</phase>
<goals>
<goal>run-specs</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Spec.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.specs2</groupId>
<artifactId>specs2_2.10</artifactId>
<version>1.14</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.10.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
view raw pom.xml hosted with ❤ by GitHub


May 29, 2013

error: src refspec master does not match any.

When I executed the following command, I got an error.
#] git push origin env-properites
  error: src refspec env-properites does not match any.
  error: failed to push some refs to 'http://localhost/mygit/firsttest.git'

I can solve this problem by doing as here is written. It is easy!
Just modify unnecessary file like .gitignore.
And add & commit.
Run the above command again.

You can see the following message.
  Compressing objects: 100% (8/8), done.   Writing objects: 100% (12/12), 1.82 KiB, done.   Total 12 (delta 2), reused 0 (delta 0)   To http://localhost/mygit/firsttest.git    * [new branch]      env-properties -> env-properties

May 16, 2013

com.aerospike.client.AerospikeException: Error Code 13: Record too big

Recently I am trying to verify Aerospike can satisfy our requirements -
1. Persistent Cache for images
2. Time To Live(TTL)
3. Eviction
4. Remove all of related data by a key
5. Scale Out easily

I am testing it with YCSB to check performance. When I tried 256KB data size test, YCSB just stopped. As you know, YCSB is not kind. It doesn't show me any error message. So I ran the following code.

You can find out how to use Aerospike client here.
package com.bae;
import com.aerospike.client.*;
import com.aerospike.client.policy.WritePolicy;
import java.io.*;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author BJ2(Joongjin Bae)
* @version $Rev: $Rev$ By $Author: BJ2 A.K.A. bae_joongjin $
* $Date: 13/05/16 11:47 $
* @since 13/05/16
*/
public class Main {
private static String NAME_SPACE = "test";
private static String SET = "YCSB";
public static void main(String[] args) {
AtomicInteger counter = new AtomicInteger();
AerospikeClient client = null;
byte[] data = getOriginalData("486KB.jpg");
System.out.println(data.length / 1024);
try {
client = new AerospikeClient("localhost", 3000);
WritePolicy policy = new WritePolicy();
policy.timeout = 50;
Key key = new Key(NAME_SPACE, SET, "user" + counter.getAndIncrement());
Bin bin = new Bin("field0", data);
System.out.println(bin.value.estimateSize() / 1024);
client.put(policy, key, bin);
} catch (AerospikeException e) {
e.printStackTrace();
}
client.close();
}
public static byte[] getOriginalData(final String path) {
FileInputStream fis = null;
try {
fis = new FileInputStream(new File(path));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
try {
for (int readNum; (readNum = fis.read(buf)) != -1;) {
bos.write(buf, 0, readNum); //no doubt here is 0
}
} catch (IOException ex) {
}
return bos.toByteArray();
}
}
view raw aeroclient.java hosted with ❤ by GitHub


The result was "Record too big".
com.aerospike.client.AerospikeException: Error Code 13: Record too big
at com.aerospike.client.command.SingleCommand.parseResult(SingleCommand.java:262)
at com.aerospike.client.command.Command.execute(Command.java:181)
at com.aerospike.client.command.SingleCommand.write(SingleCommand.java:95)
at com.aerospike.client.AerospikeClient.put(AerospikeClient.java:226)
at com.bae.Main.main(Main.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
view raw gistfile1.java hosted with ❤ by GitHub


What? I already ran same test case on AWS and had no problem. They say "The size of the object or record is exceeding the limit, currently at 1MB". I just ran 256KB and 456KB. Something is wrong. I tried applying several data size files to find out MAX_SIZE. MAX_SIZE was 128KB. Finally I got a hint to solve this problem.

citrusleaf.conf
namespace test {
replication-factor 1
high-water-memory-pct 80
high-water-disk-pct 75
stop-writes-pct 85
memory-size 12884901888
default-ttl 864000
storage-engine device {
file /var/data/citrusleaf/test.data
filesize 858993459200
data-in-memory false
write-block-size 131072 # Here!!!
defrag-period 120
defrag-lwm-pct 50
defrag-max-blocks 4000
defrag-startup-minimum 10
}
}
view raw citrusleaf.conf hosted with ❤ by GitHub

I am using data file because server was already configured RAID 10 with 4 SSDs and I did not want to go far far our data center. :) Anyway the reason was [write-block-size]. It makes limitation on using data file. When I use raw device([device]), I had no problem. I removed it and could run my test case.

You know what?  The max size of our images is 10MB. orz... 


Apr 18, 2013

java: invalid flag: -target=1.6 intellij idea

When I ran my test cases, I got this message "error: java: invalid flag: -target=1.6". I search this -"target=1.6" phrase in my project. So I re installed Intellij idea and removed .idea directory and .iml file. But I got same messages.
Finally I solved this problem by removing Additional command line parameters of java compiler.


Apr 11, 2013

How to add new node to an existing Aerospike Cluster - Using multicast

Modify /etc/citrusleaf/citrusleaf.conf as my example.
network {
service {
address any
port 3000
reuse-address
network-interface-name bond0x #If you use non standard interface name, Use this config.
#standard interface e.g. eth0, bond0, WLAN0.
}
heartbeat {
mode multicast
address 239.1.99.108
port 9918
interface-address 172.28.206.72 #You must set this config,
#if you wnat to add new node to an existing cluster.
#Each node must have unique ip address!!!
#Just set this config as node's ip addres.
interval 150
timeout 15
}
fabric {
address any
port 3001
}
info {
address any
port 3003
}
}
view raw citrusleaf.conf hosted with ❤ by GitHub

After modifying just start new node, it will be added an existing cluster automatically. You can confirm it on /var/log/citrusleaf.log with the following message.
Apr 11 2013 08:10:42 GMT: INFO (info): (base/thr_info.c:3078)  migrates in progress ( 1426 , 0 ) ::: ClusterSize 2 ::: objects 1
view raw gistfile1.md hosted with ❤ by GitHub


Tip(?).
I changed ip address to 172.28.206.73 - it's wrong address -,  after I got succeeded with above configuration. So I fixed it to 172.28.206.72 and restarted node. But I got some non normal message.
I issued the command and failed to get expected result - ClusterSize 2 -.
Apr 11 2013 05:17:23 GMT: INFO (paxos): (fabric/paxos.c:1948) Cluster Integrity Check: Detected succession list discrepancy between node bb9f5e6171cb190 and self bb935d8171cb190
Apr 11 2013 05:17:23 GMT: INFO (paxos): (fabric/paxos.c:1990) CLUSTER INTEGRITY FAULT. [Phase 1 of 2] To fix, issue this command across all nodes:  dun:nodes=bb9f5e6171cb190
Apr 11 2013 05:17:24 GMT: INFO (info): (base/thr_info.c:3071)  system memory: free 12087228kb ( 99 percent free )
Apr 11 2013 05:17:24 GMT: INFO (info): (base/thr_info.c:3078)  migrates in progress ( 0 , 0 ) ::: ClusterSize 1 ::: objects 0

$ clinfo -v 'dun:nodes=bb9f5e6171cb190'

Apr 11 2013 08:26:27 GMT: INFO (info): (base/thr_info.c:3078)  migrates in progress ( 0 , 0 ) ::: ClusterSize 1 ::: objects 1
view raw gistfile1.md hosted with ❤ by GitHub

I fixed this event by restarting all nodes.

Install and Run Aerospike Community Edition on CentOS 6.2

This installation is just for CentOS 6.2. If you use other OS like Ubuntu, please see Aerospike Standard Installation.

Step 1. Download Aerospike Database Server rpm packages
You can download here.

Step 2. Untar file
$ tar -xzf citrusleaf-community-server-2.6.0-el6.tgz


Step 3. Install the Aerospike Server
$ sudo rpm -i citrusleaf-community-tools-2.6.0-1.el6.x86_64.rpm
$ sudo rpm -i citrusleaf-community-server-2.6.0-1.el6.x86_64.rpm


Step 4. Run the Aerospike Server for Testing
$ sudo /etc/init.d/citrusleaf start
[sudo] password for me:
Starting citrusleaf: [ OK ]
$ sudo /etc/init.d/citrusleaf status
cld は停止しています
view raw .sh hosted with ❤ by GitHub

Oops! I got a error message. It means "CLD is stopped!".  Let me see the log.
Apr 11 2013 02:58:17 GMT: WARNING (cf:misc): (id.c:163) can't get physical address, tried eth, bond, wlan. fatal: 19 No such device
Apr 11 2013 02:58:17 GMT: CRITICAL GLOBAL (config): (base/cfg.c:687) could not get unique id and/or ip address
critical error: backtrace: frame 0 /usr/bin/cld() [0x46d3ff]
critical error: backtrace: frame 1 /usr/bin/cld() [0x406f2f]
critical error: backtrace: frame 2 /usr/bin/cld() [0x403b8f]
critical error: backtrace: frame 3 /lib64/libc.so.6(__libc_start_main+0xfd) [0x3212a1ecdd]
critical error: backtrace: frame 4 /usr/bin/cld() [0x4036a9]

Aha! Aerospike can't get ip address by eth, bond, wlan. Wait! my network interface name is "bond0.2032". If they use regular expression, it would be solved. But I can't fix it, so I changed my configuration file - /etc/citrusleaf/citrusleaf.conf - as blow. I just added network-interface-name item.

......

network {
        service {
                address any
                port 3000
                reuse-address
                network-interface-name bond0.2032

......

I ran it again and got succeeded.
$ sudo /etc/init.d/citrusleaf status
cld (pid 19246) を実行中...
[bae_joongjin@atlas-proxy01 ~]$ sudo grep cake /var/log/citrusleaf.log
Apr 11 2013 04:18:24 GMT: INFO (as): (base/as.c:527) service ready: soon there will be cake!
view raw successStart.sh hosted with ❤ by GitHub


Step 5. Verify Installation
I used the Aerospike command line interface tool to verity installation. It is installed as /opt/citrusleaf/bin/cli and lined in /usr/bin/cli. So you can use it normally.
$ cli -h 127.0.0.1 -n test -o set -k Aerospike -b name -v "Aerospike, Inc."
succeeded: key = Aerospike set= bin= name value= Aerospike, Inc.
$ cli -h 127.0.0.1 -n test -o set -k Aerospike -b address -v "Mountain View, CA 94043"
succeeded: key = Aerospike set= bin= address value= Mountain View, CA 94043
$ cli -h 127.0.0.1 -n test -o set -k Aerospike -b email -v "info@aerospike.com"
succeeded: key = Aerospike set= bin= email value= info@aerospike.com
$ cli -h 127.0.0.1 -n test -o get -k Aerospike
{'email': 'info@aerospike.com', 'name': 'Aerospike, Inc.', 'address': 'Mountain View, CA 94043'}


It's simple, right?

Apr 10, 2013

How to install Jenkins and plugins offline.

I tried to the following commands that are introduced on Installing Jenkins on Red Hat distributions.
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
sudo yum install jenkins


But I got failed. This server is not connected to internet. So I downloaded rpm package from RedHat Linux RPM packages for Jenkins and git, git-client plugins from Jenkins plugins download site to my MBA. And I uploaded them to the server and executed as blow.

sudo yum install jenkins-1.510-1.1.noarch.rpm
cp /my/local/git*.hpi /var/lib/jenkins/plugins
sudo chown jenkins:jenkins /var/lib/jenkins/plugins/git*.hpi
sudo service jenkins start




Mar 18, 2013

No runnable methods junit 4.11

I am implementing Swift(OpenStack Object Storage) Client to use Swift simply. I ran each of test cases successfully on IDE, but I ran test cases with Class. It throws the following exception messages.

java.lang.Exception: No runnable methods
at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:169)
at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:104)
at org.junit.runners.ParentRunner.validate(ParentRunner.java:355)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:57)
at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:10)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:30)
at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:24)
at swift.client.SwiftConfigTest.suite(SwiftConfigTest.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.junit.internal.runners.SuiteMethod.testFromSuiteMethod(SuiteMethod.java:35)
at org.junit.internal.runners.SuiteMethod.<init>(SuiteMethod.java:24)
at org.junit.internal.builders.SuiteMethodBuilder.runnerForClass(SuiteMethodBuilder.java:11)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:43)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
view raw gistfile1.txt hosted with ❤ by GitHub


Here is my code.
package swift.client;
import junit.framework.JUnit4TestAdapter;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
/**
* @author BJ2(Joongjin Bae)
* @version $Rev: $Rev$ By $Author: BJ2 A.K.A. bae_joongjin $
* $Date: 13/03/08 16:20 $
* @since 13/03/08
*/
public class SwiftConfigTest {
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(SwiftConfig.class);
}
@Test
public void testConfig() {
SwiftConfig config = new SwiftConfig();
assertThat(config.getConnectionTimeout(), is(3000));
}
}


I googled and searched several pages.

http://stackoverflow.com/questions/15383387/no-runnable-methods-on-junit-with-custom-annotation-and-all-tests-filtered

It says
You get this error due to the validation performed in validateInstanceMethods since computeTestMethods() returns an empty List: 

He suggested override or remove List size validation. I couldn't agree with him. Cause I have run my test cases with no problem on other projects. I read my code and error message again.

at swift.client.SwiftConfigTest.suite(SwiftConfigTest.java:17)

I felt it weird.  Because I don't need to run suite method. I removed suite method and ran all tests successfully.
Here is my right source code.
package swift.client;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
/**
* @author BJ2(Joongjin Bae)
* @version $Rev: $Rev$ By $Author: BJ2 A.K.A. bae_joongjin $
* $Date: 13/03/08 16:20 $
* @since 13/03/08
*/
public class SwiftConfigTest {
@Test
public void testConfig() {
SwiftConfig config = new SwiftConfig();
assertThat(config.getConnectionTimeout(), is(3000));
}
}
view raw gistfile1.java hosted with ❤ by GitHub

Feb 7, 2013

[memo] Kill all process by uid in Linux

Sometimes flunetd porecess is not stopped by "/etc/init.d/td-agent stop".
So I executed the following command.
killall -9 -u td-agent
view raw gistfile1.sh hosted with ❤ by GitHub

Feb 5, 2013

bash while loopの変数が初期化される問題

業務上処理件数を調べる必要があったため軽くスクリプトを書くつもりが変数が初期化される現象に遭遇してはまった。

最初書いたスクリプトはこちらです。
#!/bin/sh
LIST=ls /usr/local/tomcat/logs/logs.log.2013-*-*.gz > ./targetlist.txt
count=0
sed -e "s/#.*//" -e "s/^\s*$//" $LIST | while read line; do
temp=`zgrep -c -E -i -w 'target1|target2' $line`
count=$(($count + $temp))
echo "$count"
done
echo "$count"
view raw oddbash.sh hosted with ❤ by GitHub

特に問題ないように見えますが、最後のecho文の結果が0(zero)になります。

Google先生に聞くと下記のサイトを教えて下れました。
http://www.edwardawebb.com/linux/scope-issue-bash-loops

それで修正したスクリプトがこちら。正しくカウントできました。
#!/bin/sh
ls /usr/local/tomcat/logs/logs.log.2013-*-*.gz > ./targetlist.txt
exec 0<./targetlist.txt
count=0
while read line; do
temp=`zgrep -c -E -i -w 'target1|target2' $line`
count=$(($count + $temp))
echo "$count"
done
echo "$count"
view raw safebash.sh hosted with ❤ by GitHub


ではなぜこの現象が起きるかというとパイプ(|)からのstdinはいつもsubshellを使うそうです。なのでループの中のcountはループ内の変数になってしまいます。
while文前パイプを使った場合よく起きるそうです。w

上で修正したスクリプトは自分のスタイルではないので下記のように見やすく修正しました。
#!/bin/sh
RESULT=`ls /usr/local/tomcat/logs/logs.log.2013-*-*.gz`
count=0
while read line; do
temp=`zgrep -c -E -i -w 'target1|target2' $line`
count=$(($count + $temp))
echo "$count"
done <<< "$RESULT"
echo "$count"
view raw finalscript.sh hosted with ❤ by GitHub