|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.iotdb.db.subscription.broker; |
| 21 | + |
| 22 | +import org.apache.iotdb.commons.pipe.agent.task.connection.UnboundedBlockingPendingQueue; |
| 23 | +import org.apache.iotdb.db.pipe.event.common.tsfile.PipeTsFileInsertionEvent; |
| 24 | +import org.apache.iotdb.db.pipe.metric.source.PipeDataRegionEventCounter; |
| 25 | +import org.apache.iotdb.pipe.api.event.Event; |
| 26 | + |
| 27 | +import org.junit.Assert; |
| 28 | +import org.junit.Test; |
| 29 | +import org.mockito.Mockito; |
| 30 | + |
| 31 | +import java.io.File; |
| 32 | + |
| 33 | +public class TsFileDeduplicationBlockingPendingQueueTest { |
| 34 | + |
| 35 | + @Test |
| 36 | + public void testDifferentPathsWithSameHashCodeAreNotDeduplicated() { |
| 37 | + final UnboundedBlockingPendingQueue<Event> inputPendingQueue = |
| 38 | + new UnboundedBlockingPendingQueue<>(new PipeDataRegionEventCounter()); |
| 39 | + final TsFileDeduplicationBlockingPendingQueue queue = |
| 40 | + new TsFileDeduplicationBlockingPendingQueue(inputPendingQueue); |
| 41 | + |
| 42 | + final PipeTsFileInsertionEvent firstEvent = Mockito.mock(PipeTsFileInsertionEvent.class); |
| 43 | + Mockito.when(firstEvent.getTsFile()).thenReturn(new CollidingFile("first.tsfile")); |
| 44 | + Mockito.when(firstEvent.isGeneratedByHistoricalExtractor()).thenReturn(false); |
| 45 | + |
| 46 | + final PipeTsFileInsertionEvent secondEvent = Mockito.mock(PipeTsFileInsertionEvent.class); |
| 47 | + Mockito.when(secondEvent.getTsFile()).thenReturn(new CollidingFile("second.tsfile")); |
| 48 | + Mockito.when(secondEvent.isGeneratedByHistoricalExtractor()).thenReturn(true); |
| 49 | + |
| 50 | + queue.directOffer(firstEvent); |
| 51 | + queue.directOffer(secondEvent); |
| 52 | + |
| 53 | + Assert.assertSame(firstEvent, queue.waitedPoll()); |
| 54 | + Assert.assertSame(secondEvent, queue.waitedPoll()); |
| 55 | + } |
| 56 | + |
| 57 | + private static class CollidingFile extends File { |
| 58 | + |
| 59 | + private CollidingFile(final String pathname) { |
| 60 | + super(pathname); |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public int hashCode() { |
| 65 | + return 0; |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments