1414
1515package org .hyperledger .fabric .sdk ;
1616
17+ import java .util .concurrent .Executors ;
18+ import java .util .concurrent .SynchronousQueue ;
19+ import java .util .concurrent .ThreadPoolExecutor ;
20+ import java .util .concurrent .TimeUnit ;
1721
1822import org .hyperledger .fabric .sdk .exception .InvalidArgumentException ;
1923import org .hyperledger .fabric .sdk .helper .Config ;
2630import org .junit .Test ;
2731
2832import static org .hyperledger .fabric .sdk .testutils .TestUtils .resetConfig ;
33+ import static org .junit .Assert .assertSame ;
2934
3035public class ClientTest {
3136 private static final String CHANNEL_NAME = "channel1" ;
@@ -34,7 +39,6 @@ public class ClientTest {
3439 private static final String USER_NAME = "MockMe" ;
3540 private static final String USER_MSP_ID = "MockMSPID" ;
3641
37-
3842 @ BeforeClass
3943 public static void setupClient () throws Exception {
4044 try {
@@ -60,7 +64,7 @@ public void testNewChannel() {
6064 }
6165 }
6266
63- @ Test (expected = InvalidArgumentException .class )
67+ @ Test (expected = InvalidArgumentException .class )
6468 public void testSetNullChannel () throws InvalidArgumentException {
6569 hfclient .newChannel (null );
6670 Assert .fail ("Expected null channel to throw exception." );
@@ -77,7 +81,7 @@ public void testNewPeer() {
7781 }
7882 }
7983
80- @ Test (expected = InvalidArgumentException .class )
84+ @ Test (expected = InvalidArgumentException .class )
8185 public void testBadURL () throws InvalidArgumentException {
8286 hfclient .newPeer ("peer_" , " " );
8387 Assert .fail ("Expected peer with no channel throw exception" );
@@ -94,13 +98,13 @@ public void testNewOrderer() {
9498 }
9599 }
96100
97- @ Test (expected = InvalidArgumentException .class )
101+ @ Test (expected = InvalidArgumentException .class )
98102 public void testBadAddress () throws InvalidArgumentException {
99103 hfclient .newOrderer ("xx" , "xxxxxx" );
100104 Assert .fail ("Orderer allowed setting bad URL." );
101105 }
102106
103- @ Test (expected = InvalidArgumentException .class )
107+ @ Test (expected = InvalidArgumentException .class )
104108 public void testBadCryptoSuite () throws InvalidArgumentException {
105109 HFClient .createNewInstance ()
106110 .newOrderer ("xx" , "xxxxxx" );
@@ -117,7 +121,7 @@ public void testGoodMockUser() throws Exception {
117121
118122 }
119123
120- @ Test (expected = InvalidArgumentException .class )
124+ @ Test (expected = InvalidArgumentException .class )
121125 public void testBadUserContextNull () throws Exception {
122126 HFClient client = HFClient .createNewInstance ();
123127 client .setCryptoSuite (CryptoSuite .Factory .getCryptoSuite ());
@@ -126,7 +130,7 @@ public void testBadUserContextNull() throws Exception {
126130
127131 }
128132
129- @ Test (expected = InvalidArgumentException .class )
133+ @ Test (expected = InvalidArgumentException .class )
130134 public void testBadUserNameNull () throws Exception {
131135 HFClient client = HFClient .createNewInstance ();
132136 client .setCryptoSuite (CryptoSuite .Factory .getCryptoSuite ());
@@ -137,7 +141,7 @@ public void testBadUserNameNull() throws Exception {
137141
138142 }
139143
140- @ Test (expected = InvalidArgumentException .class )
144+ @ Test (expected = InvalidArgumentException .class )
141145 public void testBadUserNameEmpty () throws Exception {
142146 HFClient client = HFClient .createNewInstance ();
143147 client .setCryptoSuite (CryptoSuite .Factory .getCryptoSuite ());
@@ -148,7 +152,7 @@ public void testBadUserNameEmpty() throws Exception {
148152
149153 }
150154
151- @ Test (expected = InvalidArgumentException .class )
155+ @ Test (expected = InvalidArgumentException .class )
152156 public void testBadUserMSPIDNull () throws Exception {
153157 HFClient client = HFClient .createNewInstance ();
154158 client .setCryptoSuite (CryptoSuite .Factory .getCryptoSuite ());
@@ -159,7 +163,7 @@ public void testBadUserMSPIDNull() throws Exception {
159163
160164 }
161165
162- @ Test (expected = InvalidArgumentException .class )
166+ @ Test (expected = InvalidArgumentException .class )
163167 public void testBadUserMSPIDEmpty () throws Exception {
164168 HFClient client = HFClient .createNewInstance ();
165169 client .setCryptoSuite (CryptoSuite .Factory .getCryptoSuite ());
@@ -170,7 +174,7 @@ public void testBadUserMSPIDEmpty() throws Exception {
170174
171175 }
172176
173- @ Test (expected = InvalidArgumentException .class )
177+ @ Test (expected = InvalidArgumentException .class )
174178 public void testBadEnrollmentNull () throws Exception {
175179 HFClient client = HFClient .createNewInstance ();
176180 client .setCryptoSuite (CryptoSuite .Factory .getCryptoSuite ());
@@ -182,7 +186,7 @@ public void testBadEnrollmentNull() throws Exception {
182186
183187 }
184188
185- @ Test (expected = InvalidArgumentException .class )
189+ @ Test (expected = InvalidArgumentException .class )
186190 public void testBadEnrollmentBadCert () throws Exception {
187191 HFClient client = HFClient .createNewInstance ();
188192 client .setCryptoSuite (CryptoSuite .Factory .getCryptoSuite ());
@@ -196,12 +200,11 @@ public void testBadEnrollmentBadCert() throws Exception {
196200
197201 }
198202
199- @ Test (expected = InvalidArgumentException .class )
203+ @ Test (expected = InvalidArgumentException .class )
200204 public void testBadEnrollmentBadKey () throws Exception {
201205 HFClient client = HFClient .createNewInstance ();
202206 client .setCryptoSuite (CryptoSuite .Factory .getCryptoSuite ());
203207
204-
205208 MockUser mockUser = TestUtils .getMockUser (USER_NAME , USER_MSP_ID );
206209
207210 Enrollment mockEnrollment = TestUtils .getMockEnrollment (null , "mockCert" );
@@ -211,6 +214,81 @@ public void testBadEnrollmentBadKey() throws Exception {
211214
212215 }
213216
217+ @ Test
218+ public void testExecutorset () throws Exception {
219+
220+ hfclient = TestHFClient .newInstance ();
221+ // ThreadPoolExecutor threadPoolExecutor = ThreadPoolExecutor()
222+ ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor (10 , 100 ,
223+ 40 , TimeUnit .valueOf ("MILLISECONDS" ),
224+ new SynchronousQueue <Runnable >(),
225+ r -> {
226+ Thread t = Executors .defaultThreadFactory ().newThread (r );
227+ t .setDaemon (true );
228+ return t ;
229+ });
230+
231+ hfclient .setExecutorService (threadPoolExecutor );
232+ assertSame (threadPoolExecutor , hfclient .getExecutorService ());
233+ Channel mychannel = hfclient .newChannel ("mychannel" );
234+ assertSame (threadPoolExecutor , mychannel .getExecutorService ());
235+
236+ }
237+
238+ @ Test (expected = InvalidArgumentException .class )
239+ public void testExecutorsetAgain () throws Exception {
240+
241+ hfclient = TestHFClient .newInstance ();
242+
243+ ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor (10 , 100 ,
244+ 40 , TimeUnit .valueOf ("MILLISECONDS" ),
245+ new SynchronousQueue <Runnable >(),
246+ r -> {
247+ Thread t = Executors .defaultThreadFactory ().newThread (r );
248+ t .setDaemon (true );
249+ return t ;
250+ });
251+
252+ hfclient .setExecutorService (threadPoolExecutor );
253+ assertSame (threadPoolExecutor , hfclient .getExecutorService ());
254+ ThreadPoolExecutor threadPoolExecutor2 = new ThreadPoolExecutor (10 , 100 ,
255+ 40 , TimeUnit .valueOf ("MILLISECONDS" ),
256+ new SynchronousQueue <Runnable >(),
257+ r -> {
258+ Thread t = Executors .defaultThreadFactory ().newThread (r );
259+ t .setDaemon (true );
260+ return t ;
261+ });
262+ hfclient .setExecutorService (threadPoolExecutor2 );
263+ }
264+
265+ @ Test (expected = InvalidArgumentException .class )
266+ public void testExecutorDefaultSet () throws Exception {
267+
268+ hfclient = TestHFClient .newInstance ();
269+
270+ ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor (10 , 100 ,
271+ 40 , TimeUnit .valueOf ("MILLISECONDS" ),
272+ new SynchronousQueue <Runnable >(),
273+ r -> {
274+ Thread t = Executors .defaultThreadFactory ().newThread (r );
275+ t .setDaemon (true );
276+ return t ;
277+ });
278+
279+ Channel badisme = hfclient .newChannel ("badisme" );
280+ badisme .getExecutorService ();
281+ hfclient .setExecutorService (threadPoolExecutor );
282+ }
283+
284+ @ Test (expected = InvalidArgumentException .class )
285+ public void testExecutorsetNULL () throws Exception {
286+
287+ hfclient = TestHFClient .newInstance ();
288+
289+ hfclient .setExecutorService (null );
290+ }
291+
214292 @ Test //(expected = InvalidArgumentException.class)
215293 @ Ignore
216294 public void testCryptoFactory () throws Exception {
0 commit comments