refactor and add all about release session

This commit is contained in:
rzs840707 2014-06-27 10:11:28 +08:00
parent 5080115875
commit 559ee106c3
7 changed files with 579 additions and 554 deletions

View File

@ -2,6 +2,7 @@ package org.bench4q.agent.plugin.basic.MongoDB;
import java.util.Arrays;
import org.apache.log4j.Logger;
import org.bench4q.agent.plugin.Constructor;
import org.bench4q.agent.plugin.Parameter;
import org.bench4q.agent.plugin.Plugin;
@ -78,14 +79,14 @@ public class MongoDBPlugin {
String propertyValue = row.getCell("propertyValue");
query.append(propertyName, propertyValue);
}
System.out.println(query);
DBCursor queryResult = table.find(query);
for (DBObject item : queryResult.toArray()) {
System.out.println(item);
}
return new MongoDBReturn(true);
} catch (Exception e) {
e.printStackTrace();
Logger.getLogger(this.getClass()).info(e, e);
return new MongoDBReturn(false);
} finally {
if (mongo != null) {

View File

@ -32,9 +32,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
public class Test_MongoDBPlugin extends TestBase {
private UUID testId = UUID.randomUUID();
//localhost", 10000
@Test
public void test_Insert() {
MongoDBPlugin mongoDBPlugin = new MongoDBPlugin("localhost", 27017,
MongoDBPlugin mongoDBPlugin = new MongoDBPlugin("m001.node.com", 27017,
"temp");
MongoDBReturn result = mongoDBPlugin
.insert(this.testId.toString(),
@ -52,7 +54,7 @@ public class Test_MongoDBPlugin extends TestBase {
mongoDB.setId(pluginId);
mongoDB.setName("MongoDBPlugin");
mongoDB.setParameters(Arrays.asList(
ParameterModel.createParameter("hostName", "localhost"),
ParameterModel.createParameter("hostName", "m001.node.com"),
ParameterModel.createParameter("port", "27017"),
ParameterModel.createParameter("dbName", "temp")));
scenarioModel.getUsePlugins().add(mongoDB);

View File

@ -35,7 +35,7 @@ public class Test_Scenario extends TestBase {
@Test
public void test_RealScenario() throws IOException {
BehaviorModel[] behaviors = new BehaviorModel[28];
BehaviorModel[] behaviors = new BehaviorModel[29];
for (int i = 0; i < 9; i++) {
behaviors[3 * i] = BehaviorModel.ControlBehaviorBuilder(3 * i,
"Next", "UUID_0", Collections.<ParameterModel> emptyList());
@ -51,15 +51,21 @@ public class Test_Scenario extends TestBase {
ParameterModel.createParameter("key",
"${UUID_0:var}"),
ParameterModel
.createParameter("value",
"asdfasdfasfasdfasdfgagasdfasdfasdfagasdgasdgasdf")));
.createParameter(
"value",
"828731929090399688663513844419156517791913487136162075054396888608979390802698967398774976538053071265086303536432973027547398485897859650637839199967916419278859657562410371550970990533755543895317958490879810955359859803793616914752497927102101107393602107374624265703167902037562601756290624400217677905796841586506540830996528039667809341170671731917392828543425909887469350859806312812589702773082295018742634842159778009485901428286815715514440370336211621120027294867866046842579395402354849290925687231979896816952130161564546780855710443002842992917011602246580128072986737704758180050405202976240171827695507627799312781883033823819663102843159141022325482803101497005554269652897365593399081219143594918151989844361363454642099858085072470136971359171934346214072016627940215525657780835264287095014748952849011967941296078931973149033644269161629346531549579584063826798825958153903463232155174301997795504543310963155667642944030315802981522872371957377604512253881055347955240594154853114826089693318722619283530276507503")));
}
behaviors[27] = BehaviorModel.UserBehaviorBuilder(27, "Query",
"MongoDBPlugin_0",
Arrays.asList(ParameterModel.createParameter("properties",
"propertyName=key|propertyValue=${Context_0:var}")));
behaviors[28] = BehaviorModel.TimerBehaviorBuilder(28, "Sleep",
"Timer_0",
Arrays.asList(ParameterModel.createParameter("time", "10")));
RunScenarioModel runScenarioModel = buildRunScenarioModelWith(
Arrays.asList(
new UsePluginModel("Timer_0", "ConstantTimer",
Collections.<ParameterModel> emptyList()),
new UsePluginModel("UUID_0", "UUID", null),
new UsePluginModel("Context_0", "Context", null),
new UsePluginModel("MongoDBPlugin_0", "MongoDBPlugin",

View File

@ -70,6 +70,8 @@ public class AgentRepository extends AbstractRepositoty {
transaction.rollback();
logger.error(ExceptionLog.getStackTrace(e));
return false;
} finally {
releaseSession(session);
}
}

View File

@ -60,7 +60,6 @@ public class TestPlanRepository extends AbstractRepositoty {
}
}
@Override
protected void guardOtherUniqueConditionForEntity(
String uniquePropertyName, String value)
@ -90,9 +89,7 @@ public class TestPlanRepository extends AbstractRepositoty {
transaction.rollback();
return false;
} finally {
if (session != null) {
session.close();
}
releaseSession(session);
}
}

View File

@ -28,12 +28,12 @@ public class TestPlanScriptResultService {
private static Logger logger = Logger
.getLogger(TestPlanScriptResultService.class);
public SessionHelper getSessionHelper() {
private SessionHelper getSessionHelper() {
return sessionHelper;
}
@Autowired
public void setSessionHelper(SessionHelper sessionHelper) {
private void setSessionHelper(SessionHelper sessionHelper) {
this.sessionHelper = sessionHelper;
}
@ -61,6 +61,10 @@ public class TestPlanScriptResultService {
}
} catch (Exception e) {
logger.error(ExceptionLog.getStackTrace(e));
} finally {
if (session != null) {
session.close();
}
}
return result;
}
@ -96,6 +100,10 @@ public class TestPlanScriptResultService {
testPlanScriptResult.getResultContent());
} catch (Exception e) {
logger.error(ExceptionLog.getStackTrace(e));
} finally {
if (session != null) {
session.close();
}
}
return new ScriptBehaviorsBriefModel();
}
@ -132,6 +140,10 @@ public class TestPlanScriptResultService {
testPlanScriptResult.getResultContent());
} catch (Exception e) {
logger.error(ExceptionLog.getStackTrace(e));
} finally {
if (session != null) {
session.close();
}
}
return result;
}

View File

@ -45,17 +45,23 @@ public class TestResultSave {
public void update(TestPlan testPlan, List<Object> messages) {
Session session = this.getSessionHelper().openSession();
try {
TestPlan testPlanFromRepo = this.getTestPlanRepository()
.doGetTestPlanBy(session,
UUID.fromString(testPlan.getTestPlanRunId()));
updateTestPlanResult(messages, testPlanFromRepo);
saveUpdatedResult(testPlanFromRepo, session);
} catch (Exception e) {
Logger.getLogger(this.getClass()).info(e, e);
} finally {
if (session != null) {
session.close();
}
}
}
private void updateTestPlanResult(List<Object> messages,
TestPlan testPlanFromRepo) {
for (Object message : messages) {
if (message == null)
return;
@ -98,7 +104,6 @@ public class TestResultSave {
private boolean saveUpdatedResult(TestPlan testPlan, Session session) {
try {
getTestPlanRepository().doUpdateEntity(session, testPlan);
return true;
} catch (Exception e) {