Skip to content

Commit 2fb00fe

Browse files
author
brianmc
committed
added MT Test
1 parent ca9786a commit 2fb00fe

File tree

3 files changed

+116
-2
lines changed

3 files changed

+116
-2
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
33
<properties>
4-
<sdkVersion>1.9.0</sdkVersion>
4+
<sdkVersion>1.9.1-SNAPSHOT</sdkVersion>
55
</properties>
66
<modelVersion>4.0.0</modelVersion>
77
<groupId>net.authorize.sample</groupId>
@@ -14,7 +14,7 @@
1414
<dependency>
1515
<groupId>net.authorize</groupId>
1616
<artifactId>anet-java-sdk</artifactId>
17-
<version>${sdkVersion}</version>
17+
<version>1.9.0</version>
1818
</dependency>
1919
<dependency>
2020
<groupId>junit</groupId>
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package net.authorize.sample.PaymentTransactions;
2+
3+
import java.math.BigDecimal;
4+
import java.math.RoundingMode;
5+
import java.security.SecureRandom;
6+
import java.text.DecimalFormat;
7+
import java.util.Date;
8+
import java.util.concurrent.ExecutorService;
9+
import java.util.concurrent.Executors;
10+
11+
import net.authorize.Environment;
12+
import net.authorize.api.contract.v1.*;
13+
import net.authorize.api.controller.CreateTransactionController;
14+
import net.authorize.api.controller.base.ApiOperationBase;
15+
import net.authorize.sample.CustomerProfiles.CreateCustomerPaymentProfile;
16+
import net.authorize.sample.CustomerProfiles.CreateCustomerProfile;
17+
18+
public class ChargeCustomerProfilesMT {
19+
20+
private static final int MYTHREADS = 120;
21+
private static String apiLoginId = "5KP3u95bQpv";
22+
private static String transactionKey = "346HZ32z3fP4hTG2";
23+
24+
static SecureRandom rgenerator = new SecureRandom();
25+
26+
private static Double getAmount()
27+
{
28+
double d = (double)(1.05 + (450.0 * rgenerator.nextDouble()));
29+
DecimalFormat df = new DecimalFormat("#.##");
30+
d = Double.valueOf(df.format(d));
31+
return d;
32+
}
33+
34+
private static String getEmail()
35+
{
36+
return rgenerator.nextInt(10000000) + "@test.com";
37+
}
38+
39+
//
40+
// Run this sample from command line with:
41+
// java -jar target/ChargeCreditCard-jar-with-dependencies.jar
42+
//
43+
public static Boolean run() {
44+
45+
46+
ExecutorService executor = Executors.newFixedThreadPool(MYTHREADS);
47+
48+
Date dt1 = new Date();
49+
for (int i = 0; i < MYTHREADS; i++) {
50+
Runnable worker = new MyRunnable();
51+
executor.execute(worker);
52+
}
53+
executor.shutdown();
54+
55+
// Wait until all threads are finish
56+
while (!executor.isTerminated()) {
57+
58+
}
59+
Date dt2 = new Date();
60+
long difference = dt2.getTime() - dt1.getTime();
61+
62+
System.out.println("\nFinished all threads : " + difference/1000 + " sec");
63+
64+
return true;
65+
}
66+
67+
public static class MyRunnable implements Runnable {
68+
69+
@Override
70+
public void run() {
71+
CreateCustomerProfileResponse response = null;
72+
CreateCustomerPaymentProfileResponse paymentProfileResponse = null;
73+
74+
try{
75+
response = (CreateCustomerProfileResponse) CreateCustomerProfile.run(apiLoginId, transactionKey, getEmail());
76+
paymentProfileResponse = (CreateCustomerPaymentProfileResponse) CreateCustomerPaymentProfile.run(apiLoginId, transactionKey, response.getCustomerProfileId());
77+
}
78+
catch (Exception e) {
79+
System.out.println("Failure in CIM calls.");
80+
System.out.println(e.getMessage());
81+
return;
82+
}
83+
84+
try {
85+
Date dt1 = new Date();
86+
System.out.println("============================================================================");
87+
System.out.println("chargeResponse Dt1: + " + dt1.toString());
88+
89+
if((response.getCustomerProfileId() != null) && (paymentProfileResponse.getCustomerPaymentProfileId() != null))
90+
{
91+
CreateTransactionResponse chargeResponse = (CreateTransactionResponse) ChargeCustomerProfile.run(apiLoginId, transactionKey,
92+
response.getCustomerProfileId(), paymentProfileResponse.getCustomerPaymentProfileId(), getAmount());
93+
}
94+
else
95+
{
96+
System.out.println("NULL PROFILE IDS.");
97+
}
98+
99+
Date dt2 = new Date();
100+
System.out.println("chargeResponse Dt2: + " + dt2.toString());
101+
102+
long difference = dt2.getTime() - dt1.getTime();
103+
System.out.println("chargeResponse Diff: " + difference/1000);
104+
System.out.println("============================================================================");
105+
} catch (Exception e) {
106+
System.out.println("Failure in charge customer profile call:");
107+
System.out.println(e.getMessage());
108+
}
109+
}
110+
}
111+
}

src/main/java/net/authorize/sample/SampleCode.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ private static void RunMethod(String methodName)
197197
case "ChargeCustomerProfile":
198198
ChargeCustomerProfile.run(apiLoginId, transactionKey, customerProfileId, customerPaymentProfileId, amount);
199199
break;
200+
case "ChargeCustomerProfilesMT":
201+
ChargeCustomerProfilesMT.run();
202+
break;
200203
case "CreateSubscription":
201204
CreateSubscription.run(apiLoginId, transactionKey, (short)12, amount);
202205
break;

0 commit comments

Comments
 (0)