1 /*******************************************************************************
\r
2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
10 * http://www.apache.org/licenses/LICENSE-2.0
\r
12 * Unless required by applicable law or agreed to in writing, software
\r
13 * distributed under the License is distributed on an "AS IS" BASIS,
\r
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
15 * See the License for the specific language governing permissions and
\r
16 * limitations under the License.
\r
17 * ============LICENSE_END=========================================================
\r
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
21 *******************************************************************************/
\r
23 package com.att.nsa.mr.client.impl;
\r
25 import java.io.File;
\r
26 import java.io.FileOutputStream;
\r
27 import java.io.IOException;
\r
28 import java.util.List;
\r
29 import java.util.Properties;
\r
30 import java.util.concurrent.TimeUnit;
\r
32 import org.json.JSONObject;
\r
33 import org.junit.After;
\r
34 import org.junit.Assert;
\r
35 import org.junit.Before;
\r
36 import org.junit.Test;
\r
38 import com.att.nsa.mr.client.MRClientFactory;
\r
39 import com.att.nsa.mr.client.MRPublisher.message;
\r
40 import com.att.nsa.mr.client.response.MRPublisherResponse;
\r
42 public class MRSimplerBatchPublisherTest {
\r
46 public void setUp() throws Exception {
\r
47 Properties properties = new Properties();
\r
48 properties.load(MRSimplerBatchPublisherTest.class.getClassLoader().getResourceAsStream("dme2/producer.properties"));
\r
50 String routeFilePath="dme2/preferredRoute.txt";
\r
52 File file = new File(MRSimplerBatchPublisherTest.class.getClassLoader().getResource(routeFilePath).getFile());
\r
53 properties.put("DME2preferredRouterFilePath", MRSimplerBatchPublisherTest.class.getClassLoader().getResource(routeFilePath).getFile());
\r
55 outFile = new File(file.getParent() + "/producer_tmp.properties");
\r
56 properties.store(new FileOutputStream(outFile), "");
\r
60 public void testSend() throws IOException, InterruptedException {
\r
62 final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher)MRClientFactory.createBatchingPublisher(outFile.getPath());
\r
64 //publish some messages
\r
65 final JSONObject msg1 = new JSONObject ();
\r
66 pub.send ( "MyPartitionKey", msg1.toString () );
\r
68 final List<message> stuck = pub.close ( 1, TimeUnit.SECONDS );
\r
69 if ( stuck.size () > 0 ) {
\r
70 System.out.println( stuck.size() + " messages unsent" );
\r
74 System.out.println ( "Clean exit; all messages sent." );
\r
81 public void testSendBatchWithResponse() throws IOException, InterruptedException {
\r
83 final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher)MRClientFactory.createBatchingPublisher(outFile.getPath(), true);
\r
85 //publish some messages
\r
86 final JSONObject msg1 = new JSONObject ();
\r
87 pub.send ( "MyPartitionKey", msg1.toString () );
\r
88 MRPublisherResponse pubResponse = new MRPublisherResponse();
\r
89 pub.setPubResponse(pubResponse);
\r
91 MRPublisherResponse mrPublisherResponse = pub.sendBatchWithResponse();
\r
92 Assert.assertEquals(1, mrPublisherResponse.getPendingMsgs());
\r