18 package testsuite.clusterj;
20 import java.util.ArrayList;
21 import java.util.List;
22 import java.util.Random;
24 import com.mysql.clusterj.Session;
25 import com.mysql.clusterj.annotation.Index;
26 import com.mysql.clusterj.annotation.PersistenceCapable;
27 import com.mysql.clusterj.annotation.PrimaryKey;
36 private int numberOfThreads = 6;
37 private int numberOfIterations = 5000;
38 private ThreadGroup threadGroup;
42 createSessionFactory();
49 List<Thread> threads =
new ArrayList<Thread>();
50 List<Finder> finders =
new ArrayList<Finder>();
52 threadGroup =
new ThreadGroup(
"Finder");
54 MyUncaughtExceptionHandler uncaughtExceptionHandler =
new MyUncaughtExceptionHandler();
55 Thread.setDefaultUncaughtExceptionHandler(uncaughtExceptionHandler);
57 for (
int i = 0;
i < numberOfThreads ; ++
i) {
58 Finder finder =
new Finder();
59 Thread thread =
new Thread(threadGroup, finder);
65 for (Thread t: threads) {
69 }
catch (InterruptedException e) {
70 throw new RuntimeException(
"Interrupted while joining threads.");
73 for (Throwable thrown: uncaughtExceptionHandler.getUncaughtExceptions()) {
74 error(
"Caught exception: " + thrown.getClass().getName() +
": " + thrown.getMessage());
75 StackTraceElement[] elements = thrown.getStackTrace();
76 for (StackTraceElement element: elements) {
77 error(
" at " + element.toString());
87 class Finder
implements Runnable {
89 private Random myRandom =
new Random();
93 public long getTime() {
99 if (
getDebug()) System.out.println(
"Getting session.");
100 session = sessionFactory.getSession();
101 long start = System.nanoTime();
102 if (
getDebug()) System.out.println(
"Finding " + numberOfIterations +
" subscribers.");
103 for(
int i = 0;
i < numberOfIterations;
i++ ) {
104 int r = (int) (myRandom.nextInt(4000));
107 long stop = System.nanoTime();
109 if (
getDebug()) System.out.println(
"Elapsed time for " + numberOfIterations +
" find operations: " + (time/1000000) +
"(ms.)");
112 public void find(
int id)
114 Subscriber subscriber = session.find(Subscriber.class,
String.valueOf(
id));
115 if (subscriber == null) {
118 String aImsi = subscriber.getImsi();
125 @PersistenceCapable(
table=
"subscriber")
130 void setImsi(
String imsi);
134 void setGuti(
String guti);
137 int getMme_s1ap_id();
138 void setMme_s1ap_id(
int mme_s1ap_id);
140 int getEnb_s1ap_id();
141 void setEnb_s1ap_id(
int enb_s1ap_id);
144 void setMme_teid(
int mme_teid);
147 void setSgw_teid(
String sgw_teid);
150 void setPgw_teid(
String pgw_teid);
154 void setImei(
String imei);
158 void setMsisdn(
String msisdn);
161 void setEcm_state(
String ecm_state);
164 void setEmm_state(
String emm_state);
167 void setEps_cgi(
String eps_cgi);
169 String getGlobal_enb_id();
170 void setGlobal_enb_id(
String global_enb_id);
173 void setBearer_id(
String bearer_id);
176 void setSgw_ip_addr(
String sgw_ip_addr);