jelmini commented on code in PR #2392: URL: https://github.com/apache/jackrabbit-oak/pull/2392#discussion_r2209827598
########## oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/FailedFlushTest.java: ########## @@ -0,0 +1,173 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.oak.segment; + +import org.apache.commons.lang3.RandomStringUtils; +import org.apache.jackrabbit.oak.commons.Buffer; +import org.apache.jackrabbit.oak.segment.file.FileStore; +import org.apache.jackrabbit.oak.segment.file.FileStoreBuilder; +import org.apache.jackrabbit.oak.segment.file.tar.SegmentTarManager; +import org.apache.jackrabbit.oak.segment.file.tar.SegmentTarWriter; +import org.apache.jackrabbit.oak.segment.file.tar.TarPersistence; +import org.apache.jackrabbit.oak.segment.spi.monitor.FileStoreMonitor; +import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor; +import org.apache.jackrabbit.oak.segment.spi.monitor.RemoteStoreMonitor; +import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager; +import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveWriter; +import org.jetbrains.annotations.NotNull; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +import static org.apache.jackrabbit.oak.segment.DefaultSegmentWriterBuilder.defaultSegmentWriterBuilder; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class FailedFlushTest { + + private DefaultSegmentWriter writer; + + @Rule + public TemporaryFolder folder = new TemporaryFolder(new File("target")); + + private final RandomStringUtils randomStrings = RandomStringUtils.insecure(); + private FileStore store; + private boolean failAfterSegmentWrite = false; + private boolean failBeforeSegmentWrite = false; + private final Map<UUID, Set<Integer>> segmentId2Size = new HashMap<>(); + + @Before + public void setUp() throws Exception { + store = createFileStore(); + writer = defaultSegmentWriterBuilder("test").build(store); + } + + @Test + public void repeatedFlushFailure() throws Exception { + for (int i = 0; i < 1000; i++) { + writer.writeString(randomStrings.nextAlphanumeric(16)); + } + + failBeforeSegmentWrite = true; + for (int i = 0; i < 100; i++) { + try { + writer.flush(); + fail("This flush must fail"); + } catch (IOException e) { + // expected + } + } + failBeforeSegmentWrite = false; + + // must succeed now + writer.flush(); Review Comment: It's not clear why the flush succeeds now. It could seem that it now succeeds because trivially you set `failBeforeSegmentWrite = false`. I suppose the intention of the test is to show that this last flush doesn't fail with 'Too much data for a segment`. Can we make it more explicit? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: oak-dev-unsubscr...@jackrabbit.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org