--- /dev/null
+/*******************************************************************************\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.dmaap\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * \r
+ *******************************************************************************/\r
+\r
+package com.att.nsa.mr.client.impl;\r
+\r
+import java.io.File;\r
+import java.io.FileOutputStream;\r
+import java.io.IOException;\r
+import java.util.List;\r
+import java.util.Properties;\r
+import java.util.concurrent.TimeUnit;\r
+\r
+import org.json.JSONObject;\r
+import org.junit.After;\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
+import com.att.nsa.mr.client.MRClientFactory;\r
+import com.att.nsa.mr.client.MRPublisher.message;\r
+import com.att.nsa.mr.client.response.MRPublisherResponse;\r
+\r
+public class MRSimplerBatchPublisherTest {\r
+ \r
+ File outFile;\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ Properties properties = new Properties();\r
+ properties.load(MRSimplerBatchPublisherTest.class.getClassLoader().getResourceAsStream("dme2/producer.properties"));\r
+ \r
+ String routeFilePath="dme2/preferredRoute.txt";\r
+ \r
+ File file = new File(MRSimplerBatchPublisherTest.class.getClassLoader().getResource(routeFilePath).getFile());\r
+ properties.put("DME2preferredRouterFilePath", MRSimplerBatchPublisherTest.class.getClassLoader().getResource(routeFilePath).getFile());\r
+ \r
+ outFile = new File(file.getParent() + "/producer_tmp.properties");\r
+ properties.store(new FileOutputStream(outFile), "");\r
+ }\r
+\r
+ @Test\r
+ public void testSend() throws IOException, InterruptedException {\r
+ \r
+ final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher)MRClientFactory.createBatchingPublisher(outFile.getPath()); \r
+ \r
+ //publish some messages\r
+ final JSONObject msg1 = new JSONObject ();\r
+ pub.send ( "MyPartitionKey", msg1.toString () );\r
+\r
+ final List<message> stuck = pub.close ( 1, TimeUnit.SECONDS );\r
+ if ( stuck.size () > 0 ) {\r
+ System.out.println( stuck.size() + " messages unsent" );\r
+ }\r
+ else\r
+ {\r
+ System.out.println ( "Clean exit; all messages sent." );\r
+ }\r
+ \r
+ \r
+ }\r
+\r
+ @Test\r
+ public void testSendBatchWithResponse() throws IOException, InterruptedException {\r
+ \r
+ final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher)MRClientFactory.createBatchingPublisher(outFile.getPath(), true); \r
+ \r
+ //publish some messages\r
+ final JSONObject msg1 = new JSONObject ();\r
+ pub.send ( "MyPartitionKey", msg1.toString () );\r
+ MRPublisherResponse pubResponse = new MRPublisherResponse();\r
+ pub.setPubResponse(pubResponse);\r
+ \r
+ MRPublisherResponse mrPublisherResponse = pub.sendBatchWithResponse();\r
+ Assert.assertEquals(1, mrPublisherResponse.getPendingMsgs());\r
+ \r
+ }\r
+\r
+}\r