|
32 | 32 | import static org.hamcrest.Matchers.greaterThanOrEqualTo; |
33 | 33 | import static org.hamcrest.Matchers.hasProperty; |
34 | 34 | import static org.hamcrest.Matchers.is; |
35 | | -import static org.hamcrest.Matchers.isA; |
36 | 35 | import static org.hamcrest.Matchers.lessThan; |
37 | 36 | import static org.hamcrest.core.StringContains.containsString; |
38 | 37 | import static org.hamcrest.object.HasToString.hasToString; |
39 | 38 | import static org.junit.Assert.assertEquals; |
40 | | -import static org.junit.Assert.assertFalse; |
41 | 39 | import static org.junit.Assert.assertNotNull; |
42 | 40 | import static org.junit.Assert.assertNull; |
43 | 41 | import static org.junit.Assert.assertTrue; |
44 | 42 | import static org.junit.Assert.fail; |
45 | | -import static org.mockito.ArgumentMatchers.any; |
46 | | -import static org.mockito.ArgumentMatchers.anyLong; |
47 | | -import static org.mockito.ArgumentMatchers.eq; |
48 | 43 | import static org.mockito.Mockito.mock; |
49 | 44 | import static org.mockito.Mockito.times; |
50 | 45 | import static org.mockito.Mockito.verify; |
51 | | -import static org.mockito.Mockito.verifyNoMoreInteractions; |
52 | 46 | import static org.mockito.Mockito.when; |
53 | 47 |
|
54 | 48 | import java.io.IOException; |
55 | | -import java.io.NotSerializableException; |
56 | 49 | import java.io.Serializable; |
57 | 50 | import java.lang.reflect.Proxy; |
58 | 51 | import java.nio.ByteBuffer; |
|
66 | 59 | import java.util.HashSet; |
67 | 60 | import java.util.List; |
68 | 61 | import java.util.Set; |
69 | | -import java.util.concurrent.ScheduledExecutorService; |
70 | | -import java.util.concurrent.TimeUnit; |
71 | 62 | import java.util.concurrent.atomic.AtomicInteger; |
72 | 63 | import java.util.function.Function; |
73 | 64 | import javax.jms.BytesMessage; |
|
84 | 75 | import org.apache.activemq.command.ActiveMQMessage; |
85 | 76 | import org.apache.activemq.util.Callback; |
86 | 77 | import org.apache.beam.sdk.PipelineResult; |
87 | | -import org.apache.beam.sdk.coders.Coder; |
88 | 78 | import org.apache.beam.sdk.coders.SerializableCoder; |
89 | 79 | import org.apache.beam.sdk.coders.StringUtf8Coder; |
90 | 80 | import org.apache.beam.sdk.io.UnboundedSource; |
|
94 | 84 | import org.apache.beam.sdk.metrics.MetricNameFilter; |
95 | 85 | import org.apache.beam.sdk.metrics.MetricQueryResults; |
96 | 86 | import org.apache.beam.sdk.metrics.MetricsFilter; |
97 | | -import org.apache.beam.sdk.options.ExecutorOptions; |
98 | | -import org.apache.beam.sdk.options.PipelineOptions; |
99 | 87 | import org.apache.beam.sdk.options.PipelineOptionsFactory; |
100 | | -import org.apache.beam.sdk.testing.CoderProperties; |
101 | 88 | import org.apache.beam.sdk.testing.PAssert; |
102 | 89 | import org.apache.beam.sdk.testing.TestPipeline; |
103 | 90 | import org.apache.beam.sdk.transforms.Count; |
104 | 91 | import org.apache.beam.sdk.transforms.Create; |
105 | 92 | import org.apache.beam.sdk.transforms.SerializableBiFunction; |
106 | | -import org.apache.beam.sdk.util.SerializableUtils; |
107 | 93 | import org.apache.beam.sdk.values.PCollection; |
108 | 94 | import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Throwables; |
109 | 95 | import org.apache.qpid.jms.JmsAcknowledgeCallback; |
|
117 | 103 | import org.junit.Test; |
118 | 104 | import org.junit.runner.RunWith; |
119 | 105 | import org.junit.runners.Parameterized; |
120 | | -import org.mockito.ArgumentCaptor; |
121 | 106 | import org.mockito.Mockito; |
122 | 107 | import org.slf4j.Logger; |
123 | 108 | import org.slf4j.LoggerFactory; |
@@ -163,9 +148,9 @@ public static Collection<Object[]> connectionFactories() { |
163 | 148 | private ConnectionFactory connectionFactory; |
164 | 149 | private final Class<? extends ConnectionFactory> connectionFactoryClass; |
165 | 150 | private ConnectionFactory connectionFactoryWithSyncAcksAndWithoutPrefetch; |
166 | | - private final String brokerUrl; |
167 | | - private final Integer brokerPort; |
168 | | - private final String forceAsyncAcksParam; |
| 151 | + private String brokerUrl; |
| 152 | + private String forceAsyncAcksParam; |
| 153 | + private int brokerPort; |
169 | 154 |
|
170 | 155 | public JmsIOTest( |
171 | 156 | String brokerUrl, |
@@ -252,20 +237,6 @@ public void testReadMessages() throws Exception { |
252 | 237 | assertQueueIsEmpty(); |
253 | 238 | } |
254 | 239 |
|
255 | | - @Test |
256 | | - public void testPipelineWithNonSerializableCF() { |
257 | | - SerializableUtils.ensureSerializable( |
258 | | - JmsIO.read() |
259 | | - .withConnectionFactoryProviderFn(__ -> new MockNonSerializableConnectionFactory())); |
260 | | - try { |
261 | | - SerializableUtils.ensureSerializable( |
262 | | - JmsIO.read().withConnectionFactory(new MockNonSerializableConnectionFactory())); |
263 | | - fail(); |
264 | | - } catch (Exception e) { |
265 | | - assertThat(Throwables.getRootCause(e), isA(NotSerializableException.class)); |
266 | | - } |
267 | | - } |
268 | | - |
269 | 240 | @Test |
270 | 241 | public void testReadMessagesWithCFProviderFn() throws Exception { |
271 | 242 | long count = 5; |
@@ -522,32 +493,6 @@ public void testWriteDynamicMessage() throws Exception { |
522 | 493 | assertEquals(100, count); |
523 | 494 | } |
524 | 495 |
|
525 | | - @Test |
526 | | - public void testSplitForQueue() throws Exception { |
527 | | - JmsIO.Read read = JmsIO.read().withQueue(QUEUE); |
528 | | - PipelineOptions pipelineOptions = PipelineOptionsFactory.create(); |
529 | | - int desiredNumSplits = 5; |
530 | | - JmsIO.UnboundedJmsSource initialSource = new JmsIO.UnboundedJmsSource(read); |
531 | | - List<JmsIO.UnboundedJmsSource> splits = initialSource.split(desiredNumSplits, pipelineOptions); |
532 | | - // in the case of a queue, we have concurrent consumers by default, so the initial number |
533 | | - // splits is equal to the desired number of splits |
534 | | - assertEquals(desiredNumSplits, splits.size()); |
535 | | - } |
536 | | - |
537 | | - @Test |
538 | | - public void testSplitForTopic() throws Exception { |
539 | | - JmsIO.Read read = JmsIO.read().withTopic(TOPIC); |
540 | | - PipelineOptions pipelineOptions = PipelineOptionsFactory.create(); |
541 | | - int desiredNumSplits = 5; |
542 | | - JmsIO.UnboundedJmsSource initialSource = new JmsIO.UnboundedJmsSource(read); |
543 | | - List<JmsIO.UnboundedJmsSource> splits = initialSource.split(desiredNumSplits, pipelineOptions); |
544 | | - // in the case of a topic, we can have only a unique subscriber on the topic per pipeline |
545 | | - // else it means we can have duplicate messages (all subscribers on the topic receive every |
546 | | - // message). |
547 | | - // So, whatever the desizedNumSplits is, the actual number of splits should be 1. |
548 | | - assertEquals(1, splits.size()); |
549 | | - } |
550 | | - |
551 | 496 | private boolean advanceWithRetry(UnboundedSource.UnboundedReader reader) throws IOException { |
552 | 497 | for (int attempt = 0; attempt < 10; attempt++) { |
553 | 498 | if (reader.advance()) { |
@@ -685,63 +630,6 @@ public void testCheckpointMarkAndFinalizeSeparatelyClientAcknowledgeUnsafe() thr |
685 | 630 | assertEquals(5, count(QUEUE)); |
686 | 631 | } |
687 | 632 |
|
688 | | - @Test |
689 | | - public void testJmsCheckpointMarkIndividualAcknowledgeAllMessages() throws Exception { |
690 | | - Message msg1 = Mockito.mock(Message.class); |
691 | | - Message msg2 = Mockito.mock(Message.class); |
692 | | - Message msg3 = Mockito.mock(Message.class); |
693 | | - |
694 | | - JmsCheckpointMark.Preparer preparer = |
695 | | - JmsCheckpointMark.newPreparer(JmsIO.AcknowledgeMode.INDIVIDUAL_ACKNOWLEDGE); |
696 | | - preparer.add(msg1); |
697 | | - preparer.add(msg2); |
698 | | - preparer.add(msg3); |
699 | | - |
700 | | - AtomicInteger activeCheckpoints = new AtomicInteger(0); |
701 | | - JmsCheckpointMark mark = |
702 | | - preparer.newCheckpoint( |
703 | | - null, null, JmsIO.AcknowledgeMode.INDIVIDUAL_ACKNOWLEDGE, activeCheckpoints); |
704 | | - assertNotNull(mark.getMessages()); |
705 | | - assertEquals(3, mark.getMessages().size()); |
706 | | - assertNull(mark.getConsumer()); |
707 | | - assertNull(mark.getSession()); |
708 | | - assertEquals(1, activeCheckpoints.get()); |
709 | | - |
710 | | - mark.finalizeCheckpoint(); |
711 | | - |
712 | | - Mockito.verify(msg1, Mockito.times(1)).acknowledge(); |
713 | | - Mockito.verify(msg2, Mockito.times(1)).acknowledge(); |
714 | | - Mockito.verify(msg3, Mockito.times(1)).acknowledge(); |
715 | | - assertEquals(0, activeCheckpoints.get()); |
716 | | - } |
717 | | - |
718 | | - @Test |
719 | | - public void testJmsCheckpointMarkClientAcknowledgeUnsafeNoSessionRecreation() throws Exception { |
720 | | - Message msg1 = Mockito.mock(Message.class); |
721 | | - Message msg2 = Mockito.mock(Message.class); |
722 | | - |
723 | | - JmsCheckpointMark.Preparer preparer = |
724 | | - JmsCheckpointMark.newPreparer(JmsIO.AcknowledgeMode.CLIENT_ACKNOWLEDGE_UNSAFE); |
725 | | - preparer.add(msg1); |
726 | | - preparer.add(msg2); |
727 | | - |
728 | | - AtomicInteger activeCheckpoints = new AtomicInteger(0); |
729 | | - JmsCheckpointMark mark = |
730 | | - preparer.newCheckpoint( |
731 | | - null, null, JmsIO.AcknowledgeMode.CLIENT_ACKNOWLEDGE_UNSAFE, activeCheckpoints); |
732 | | - assertNotNull(mark.getMessages()); |
733 | | - assertEquals(1, mark.getMessages().size()); |
734 | | - assertNull(mark.getConsumer()); |
735 | | - assertNull(mark.getSession()); |
736 | | - assertEquals(1, activeCheckpoints.get()); |
737 | | - |
738 | | - mark.finalizeCheckpoint(); |
739 | | - |
740 | | - Mockito.verify(msg2, Mockito.times(1)).acknowledge(); |
741 | | - Mockito.verify(msg1, Mockito.never()).acknowledge(); |
742 | | - assertEquals(0, activeCheckpoints.get()); |
743 | | - } |
744 | | - |
745 | 633 | private JmsIO.UnboundedJmsReader setupReaderForTest() throws JMSException { |
746 | 634 | return setupReaderForTest(null); |
747 | 635 | } |
@@ -890,17 +778,6 @@ public void testCheckpointMarkSafety() throws Exception { |
890 | 778 | runner.join(); |
891 | 779 | } |
892 | 780 |
|
893 | | - /** Test the checkpoint mark default coder, which is actually AvroCoder. */ |
894 | | - @Test |
895 | | - public void testCheckpointMarkDefaultCoder() throws Exception { |
896 | | - JmsCheckpointMark jmsCheckpointMark = |
897 | | - JmsCheckpointMark.newPreparer(JmsIO.AcknowledgeMode.CLIENT_ACKNOWLEDGE) |
898 | | - .newCheckpoint(null, null, JmsIO.AcknowledgeMode.CLIENT_ACKNOWLEDGE, null); |
899 | | - Coder coder = new JmsIO.UnboundedJmsSource(null).getCheckpointMarkCoder(); |
900 | | - CoderProperties.coderSerializable(coder); |
901 | | - CoderProperties.coderDecodeEncodeEqual(coder, jmsCheckpointMark); |
902 | | - } |
903 | | - |
904 | 781 | @Test |
905 | 782 | public void testDefaultAutoscaler() throws IOException { |
906 | 783 | JmsIO.Read spec = |
@@ -945,53 +822,6 @@ public void testCustomAutoscaler() throws IOException { |
945 | 822 | verify(autoScaler, times(1)).stop(); |
946 | 823 | } |
947 | 824 |
|
948 | | - @Test |
949 | | - public void testCloseWithTimeout() throws IOException, JMSException { |
950 | | - Duration closeTimeout = Duration.millis(2000L); |
951 | | - JmsIO.Read spec = |
952 | | - JmsIO.read() |
953 | | - .withConnectionFactory(connectionFactory) |
954 | | - .withUsername(USERNAME) |
955 | | - .withPassword(PASSWORD) |
956 | | - .withQueue(QUEUE) |
957 | | - .withCloseTimeout(closeTimeout); |
958 | | - |
959 | | - JmsIO.UnboundedJmsSource source = new JmsIO.UnboundedJmsSource(spec); |
960 | | - |
961 | | - ScheduledExecutorService mockScheduledExecutorService = |
962 | | - Mockito.mock(ScheduledExecutorService.class); |
963 | | - ExecutorOptions options = PipelineOptionsFactory.as(ExecutorOptions.class); |
964 | | - options.setScheduledExecutorService(mockScheduledExecutorService); |
965 | | - ArgumentCaptor<Runnable> runnableArgumentCaptor = ArgumentCaptor.forClass(Runnable.class); |
966 | | - when(mockScheduledExecutorService.schedule( |
967 | | - runnableArgumentCaptor.capture(), anyLong(), any(TimeUnit.class))) |
968 | | - .thenReturn(null /* unused */); |
969 | | - |
970 | | - JmsIO.UnboundedJmsReader reader = source.createReader(options, null); |
971 | | - reader.start(); |
972 | | - assertFalse(getDiscardedValue(reader)); |
973 | | - reader.checkpointMarkPreparer.add(Mockito.mock(Message.class)); |
974 | | - CheckpointMark mark = reader.getCheckpointMark(); |
975 | | - reader.close(); |
976 | | - assertTrue(getDiscardedValue(reader)); |
977 | | - verify(mockScheduledExecutorService) |
978 | | - .schedule(any(Runnable.class), eq(1L), eq(TimeUnit.SECONDS)); |
979 | | - mark.finalizeCheckpoint(); |
980 | | - runnableArgumentCaptor.getValue().run(); |
981 | | - assertTrue(getDiscardedValue(reader)); |
982 | | - verifyNoMoreInteractions(mockScheduledExecutorService); |
983 | | - } |
984 | | - |
985 | | - private boolean getDiscardedValue(JmsIO.UnboundedJmsReader reader) { |
986 | | - JmsCheckpointMark.Preparer preparer = reader.checkpointMarkPreparer; |
987 | | - preparer.lock.readLock().lock(); |
988 | | - try { |
989 | | - return preparer.discarded; |
990 | | - } finally { |
991 | | - preparer.lock.readLock().unlock(); |
992 | | - } |
993 | | - } |
994 | | - |
995 | 825 | @Test |
996 | 826 | public void testDiscardCheckpointMark() throws Exception { |
997 | 827 | Connection connection = |
|
0 commit comments