package com.jiuqi.mobile.core.service.service;
import java.sql.Connection;
import org.junit.Assert;
import org.junit.Test;
import com.jqmobile.core.orm.ORM;
import com.jqmobile.core.orm.exception.ORMException;
import com.jqmobile.core.server.db.DBPool;
import com.jqmobile.core.server.db.orm.ORMFactory;
import com.jqmobile.core.server.service.ServiceFactory;
import com.jqmobile.core.utils.thread.AsyncTask;
public class ServiceTest extends Assert{
int wcount=0,ecount=0;
public void testTime() throws Exception{
wcount=0;
ecount=0;
Connection conn = DBPool.getInstance().getConnection();
final ORM<CountBean> orm = ORMFactory.instance(conn, CountBean.class);
conn.setAutoCommit(true);
for(int i=0; i<1000; i++){
AsyncTask<Class<?>, Long> task = new AsyncTask<Class<?>, Long>(){
@Override
protected Long doInBackground(Class<?>... params) throws Throwable {
long l = System.currentTimeMillis();
IServiceTest st = ServiceFactory.instance(IServiceTest.class);
// System.out.println("instance service: \t"+(System.currentTimeMillis()-l));
st.testLogin("username", "password");
return System.currentTimeMillis()-l;
}
@Override
protected void onPostExecute(Long result) {
// // super.onPostExecute(result);
CountBean b = new CountBean(result);
try {
orm.insert(b);
} catch (ORMException e) {
e.printStackTrace();
}
if(result > 10 && result <100){
System.out.println("instance service: \t"+(result));
wcount++;
}else if(result>=100){
System.err.println("instance service: \t"+(result));
ecount++;
}
}
@Override
protected void onException(Throwable e) {
e.printStackTrace();
}
};
long l = System.currentTimeMillis();
task.execute(IServiceTest.class);
l = System.currentTimeMillis()-l;
if(l>100){
System.err.println("=============add async task time:\t"+l);
}
}
while(true){
try {
Thread.sleep(1000);
System.out.println("=============================thread count:\t"+AsyncTask.getThreadCount());
System.out.println("=============================wcount:\t"+wcount);
System.out.println("=============================ecount:\t"+ecount);
if(0 == AsyncTask.getThreadCount()){
conn.close();
// testTime();
return;
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
// long s = System.currentTimeMillis();
// long l = System.currentTimeMillis();
// IServiceTest st = ServiceFactory.instance(IServiceTest.class);
// System.out.println("instance service: \t"+(System.currentTimeMillis()-l));
// try {
// st.testLogin("username", "password");
// System.out.println("all time: \t"+(System.currentTimeMillis()-l));
// } catch (Exception e) {
// e.printStackTrace();
// }
}
}