001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.backup.impl;
019
020import static org.junit.jupiter.api.Assertions.assertEquals;
021import static org.junit.jupiter.api.Assertions.assertTrue;
022
023import java.io.IOException;
024import java.util.List;
025import org.apache.hadoop.hbase.TableName;
026import org.apache.hadoop.hbase.backup.BackupInfo;
027import org.apache.hadoop.hbase.backup.BackupInfo.BackupState;
028import org.apache.hadoop.hbase.backup.PointInTimeRestoreRequest;
029import org.apache.hadoop.hbase.client.Connection;
030import org.junit.jupiter.api.Test;
031
032abstract class TestAbstractPitrRestoreHandlerGetBackupMetadata {
033
034  protected static final String TABLE_NAME = "table";
035  protected static final List<TableName> TABLE_LIST = List.of(TableName.valueOf(TABLE_NAME));
036
037  protected Connection mockConn;
038  protected PointInTimeRestoreRequest request;
039
040  protected BackupInfo getBackupInfo(BackupState state) {
041    BackupInfo info = new BackupInfo();
042    info.setState(state);
043    return info;
044  }
045
046  protected abstract List<PitrBackupMetadata>
047    callGetBackupMetadataWithBackupStates(BackupState... states) throws IOException;
048
049  @Test
050  void testGetBackupMetadataFiltersNonCompleteBackups() throws IOException {
051    List<PitrBackupMetadata> result = callGetBackupMetadataWithBackupStates(BackupState.COMPLETE,
052      BackupState.FAILED, BackupState.RUNNING);
053
054    assertEquals(1, result.size());
055    assertEquals("backup_0", result.get(0).getBackupId());
056  }
057
058  @Test
059  void testGetBackupMetadataReturnsEmptyWhenNoCompleteBackups() throws IOException {
060    List<PitrBackupMetadata> result = callGetBackupMetadataWithBackupStates(BackupState.RUNNING);
061
062    assertTrue(result.isEmpty());
063  }
064
065  @Test
066  void testGetBackupMetadataReturnsAllWhenAllComplete() throws IOException {
067    List<PitrBackupMetadata> result =
068      callGetBackupMetadataWithBackupStates(BackupState.COMPLETE, BackupState.COMPLETE);
069
070    assertEquals(2, result.size());
071    assertEquals("backup_0", result.get(0).getBackupId());
072    assertEquals("backup_1", result.get(1).getBackupId());
073  }
074}