|
| 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, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + * |
| 18 | + */ |
| 19 | +package org.apache.hadoop.ozone.om.service; |
| 20 | + |
| 21 | + |
| 22 | +import org.apache.hadoop.hdds.conf.OzoneConfiguration; |
| 23 | +import org.apache.hadoop.hdds.scm.protocol.ScmBlockLocationProtocol; |
| 24 | +import org.apache.hadoop.ozone.om.KeyManagerImpl; |
| 25 | +import org.apache.hadoop.ozone.om.OmMetadataManagerImpl; |
| 26 | +import org.apache.hadoop.ozone.om.OmSnapshotManager; |
| 27 | +import org.apache.hadoop.ozone.om.OzoneManager; |
| 28 | +import org.apache.hadoop.ozone.om.SnapshotChainManager; |
| 29 | +import org.apache.hadoop.ozone.om.helpers.SnapshotInfo; |
| 30 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 31 | +import org.junit.jupiter.params.ParameterizedTest; |
| 32 | +import org.junit.jupiter.params.provider.Arguments; |
| 33 | +import org.junit.jupiter.params.provider.MethodSource; |
| 34 | +import org.mockito.Mock; |
| 35 | +import org.mockito.Mockito; |
| 36 | +import org.mockito.junit.jupiter.MockitoExtension; |
| 37 | + |
| 38 | +import java.io.IOException; |
| 39 | +import java.time.Duration; |
| 40 | +import java.util.stream.Stream; |
| 41 | + |
| 42 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 43 | + |
| 44 | +/** |
| 45 | + * Class to unit test SnapshotDeletingService. |
| 46 | + */ |
| 47 | +@ExtendWith(MockitoExtension.class) |
| 48 | +public class TestSnapshotDeletingService { |
| 49 | + @Mock |
| 50 | + private OzoneManager ozoneManager; |
| 51 | + @Mock |
| 52 | + private KeyManagerImpl keyManager; |
| 53 | + @Mock |
| 54 | + private OmSnapshotManager omSnapshotManager; |
| 55 | + @Mock |
| 56 | + private SnapshotChainManager chainManager; |
| 57 | + @Mock |
| 58 | + private OmMetadataManagerImpl omMetadataManager; |
| 59 | + @Mock |
| 60 | + private ScmBlockLocationProtocol scmClient; |
| 61 | + private final OzoneConfiguration conf = new OzoneConfiguration();; |
| 62 | + private final long sdsRunInterval = Duration.ofMillis(1000).toMillis(); |
| 63 | + private final long sdsServiceTimeout = Duration.ofSeconds(10).toMillis(); |
| 64 | + |
| 65 | + |
| 66 | + private static Stream<Arguments> testCasesForIgnoreSnapshotGc() { |
| 67 | + SnapshotInfo filteredSnapshot = SnapshotInfo.newBuilder().setSstFiltered(true).setName("snap1").build(); |
| 68 | + SnapshotInfo unFilteredSnapshot = SnapshotInfo.newBuilder().setSstFiltered(false).setName("snap1").build(); |
| 69 | + return Stream.of( |
| 70 | + Arguments.of(filteredSnapshot, SnapshotInfo.SnapshotStatus.SNAPSHOT_DELETED, true, false), |
| 71 | + Arguments.of(filteredSnapshot, SnapshotInfo.SnapshotStatus.SNAPSHOT_ACTIVE, true, true), |
| 72 | + Arguments.of(unFilteredSnapshot, SnapshotInfo.SnapshotStatus.SNAPSHOT_DELETED, true, true), |
| 73 | + Arguments.of(unFilteredSnapshot, SnapshotInfo.SnapshotStatus.SNAPSHOT_ACTIVE, true, true), |
| 74 | + Arguments.of(filteredSnapshot, SnapshotInfo.SnapshotStatus.SNAPSHOT_DELETED, false, false), |
| 75 | + Arguments.of(unFilteredSnapshot, SnapshotInfo.SnapshotStatus.SNAPSHOT_DELETED, false, false), |
| 76 | + Arguments.of(unFilteredSnapshot, SnapshotInfo.SnapshotStatus.SNAPSHOT_ACTIVE, false, true), |
| 77 | + Arguments.of(filteredSnapshot, SnapshotInfo.SnapshotStatus.SNAPSHOT_ACTIVE, false, true)); |
| 78 | + } |
| 79 | + |
| 80 | + @ParameterizedTest |
| 81 | + @MethodSource("testCasesForIgnoreSnapshotGc") |
| 82 | + public void testProcessSnapshotLogicInSDS(SnapshotInfo snapshotInfo, |
| 83 | + SnapshotInfo.SnapshotStatus status, |
| 84 | + boolean sstFilteringServiceEnabled, |
| 85 | + boolean expectedOutcome) |
| 86 | + throws IOException { |
| 87 | + Mockito.when(keyManager.isSstFilteringSvcEnabled()).thenReturn(sstFilteringServiceEnabled); |
| 88 | + Mockito.when(omMetadataManager.getSnapshotChainManager()).thenReturn(chainManager); |
| 89 | + Mockito.when(ozoneManager.getKeyManager()).thenReturn(keyManager); |
| 90 | + Mockito.when(ozoneManager.getOmSnapshotManager()).thenReturn(omSnapshotManager); |
| 91 | + Mockito.when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager); |
| 92 | + Mockito.when(ozoneManager.getConfiguration()).thenReturn(conf); |
| 93 | + |
| 94 | + SnapshotDeletingService snapshotDeletingService = |
| 95 | + new SnapshotDeletingService(sdsRunInterval, sdsServiceTimeout, ozoneManager, scmClient); |
| 96 | + |
| 97 | + snapshotInfo.setSnapshotStatus(status); |
| 98 | + assertEquals(expectedOutcome, snapshotDeletingService.shouldIgnoreSnapshot(snapshotInfo)); |
| 99 | + } |
| 100 | +} |
0 commit comments