|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Alibaba Group Holding Ltd. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.alibaba.fluss.record; |
| 18 | + |
| 19 | +import com.alibaba.fluss.memory.MemorySegment; |
| 20 | + |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | + |
| 23 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 24 | + |
| 25 | +/** Tests for {@link ChangeTypeVectorWriter}. */ |
| 26 | +public class ChangeTypeVectorWriterTest { |
| 27 | + |
| 28 | + @Test |
| 29 | + public void testReproduceOriginalIndexOutOfBoundsExceptionScenario() { |
| 30 | + int segmentSize = 131072; // 128KB |
| 31 | + MemorySegment segment = MemorySegment.allocateHeapMemory(segmentSize); |
| 32 | + |
| 33 | + // Create a ChangeTypeVectorWriter that uses the entire segment |
| 34 | + ChangeTypeVectorWriter writer = new ChangeTypeVectorWriter(segment, 0); |
| 35 | + |
| 36 | + // Write records up to capacity |
| 37 | + for (int i = 0; i < segmentSize; i++) { |
| 38 | + writer.writeChangeType(ChangeType.INSERT); |
| 39 | + } |
| 40 | + |
| 41 | + // This should now throw IllegalStateException instead of IndexOutOfBoundsException |
| 42 | + assertThatThrownBy(() -> writer.writeChangeType(ChangeType.INSERT)) |
| 43 | + .isInstanceOf(IllegalStateException.class) |
| 44 | + .hasMessage("The change type vector is full."); |
| 45 | + } |
| 46 | +} |
0 commit comments