-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#7988][2.4][Platform] Make delete backup task best effort.
Summary: Backport for ignoring backup deletion failures. Original commit: D11207 / 9d00b8b Test Plan: Unit test Reviewers: spotachev, wesley Reviewed By: wesley Subscribers: jenkins-bot, yugaware Differential Revision: https://phabricator.dev.yugabyte.com/D11224
- Loading branch information
Showing
5 changed files
with
205 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
managed/src/test/java/com/yugabyte/yw/commissioner/tasks/DeleteBackupTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Copyright 2021 YugaByte, Inc. and Contributors | ||
* | ||
* Licensed under the Polyform Free Trial License 1.0.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://github.com/YugaByte/yugabyte-db/blob/master/licenses/POLYFORM-FREE-TRIAL-LICENSE-1.0.0.txt | ||
*/ | ||
|
||
package com.yugabyte.yw.commissioner.tasks; | ||
|
||
import com.yugabyte.yw.common.FakeDBApplication; | ||
import com.yugabyte.yw.common.ModelFactory; | ||
import com.yugabyte.yw.common.ShellProcessHandler.ShellResponse; | ||
import com.yugabyte.yw.models.Backup; | ||
import com.yugabyte.yw.models.Customer; | ||
import com.yugabyte.yw.models.CustomerConfig; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import java.util.UUID; | ||
|
||
import static com.yugabyte.yw.models.Backup.BackupState.*; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class DeleteBackupTest extends FakeDBApplication { | ||
|
||
private Customer defaultCustomer; | ||
private Backup backup; | ||
|
||
@Before | ||
public void setUp() { | ||
UUID universeUUID = UUID.randomUUID(); | ||
defaultCustomer = ModelFactory.testCustomer(); | ||
CustomerConfig s3StorageConfig = ModelFactory.createS3StorageConfig(defaultCustomer); | ||
backup = ModelFactory.createBackup(defaultCustomer.uuid, | ||
universeUUID, s3StorageConfig.configUUID); | ||
} | ||
|
||
// Test that only backups in Complete state can be deleted. | ||
// Otherwise the run of backup task is a no-op | ||
@Test | ||
public void invalid() { | ||
assertEquals(InProgress, backup.state); | ||
DeleteBackup.Params params = new DeleteBackup.Params(); | ||
params.backupUUID = backup.backupUUID; | ||
params.customerUUID = defaultCustomer.uuid; | ||
|
||
DeleteBackup deleteBackupTask = new DeleteBackup(); | ||
deleteBackupTask.initialize(params); | ||
deleteBackupTask.run(); | ||
|
||
Backup backup = Backup.get(params.customerUUID, params.backupUUID); | ||
assertEquals(InProgress, backup.state); | ||
} | ||
|
||
@Test | ||
public void success() { | ||
backup.transitionState(Completed); | ||
DeleteBackup.Params params = new DeleteBackup.Params(); | ||
params.backupUUID = backup.backupUUID; | ||
params.customerUUID = defaultCustomer.uuid; | ||
|
||
ShellResponse shellResponse = new ShellResponse(); | ||
shellResponse.message = "{\"success\": true}"; | ||
shellResponse.code = 0; | ||
when(mockTableManager.deleteBackup(any())).thenReturn(shellResponse); | ||
|
||
DeleteBackup deleteBackupTask = new DeleteBackup(); | ||
deleteBackupTask.initialize(params); | ||
deleteBackupTask.run(); | ||
|
||
verify(mockTableManager, times(1)).deleteBackup(any()); | ||
Backup backup = Backup.get(params.customerUUID, params.backupUUID); | ||
assertEquals(Deleted, backup.state); | ||
} | ||
|
||
@Test | ||
public void failure() { | ||
backup.transitionState(Completed); | ||
DeleteBackup.Params params = new DeleteBackup.Params(); | ||
params.backupUUID = backup.backupUUID; | ||
params.customerUUID = defaultCustomer.uuid; | ||
|
||
ShellResponse shellResponse = new ShellResponse(); | ||
shellResponse.message = "{\"success\": false}"; | ||
shellResponse.code = 22; | ||
when(mockTableManager.deleteBackup(any())).thenReturn(shellResponse); | ||
|
||
DeleteBackup deleteBackupTask = new DeleteBackup(); | ||
deleteBackupTask.initialize(params); | ||
deleteBackupTask.run(); | ||
|
||
verify(mockTableManager, times(1)).deleteBackup(any()); | ||
Backup backup = Backup.get(params.customerUUID, params.backupUUID); | ||
assertEquals(FailedToDelete, backup.state); | ||
} | ||
|
||
@Test | ||
public void unexpectedException() { | ||
backup.transitionState(Completed); | ||
DeleteBackup.Params params = new DeleteBackup.Params(); | ||
params.backupUUID = backup.backupUUID; | ||
params.customerUUID = defaultCustomer.uuid; | ||
|
||
ShellResponse shellResponse = new ShellResponse(); | ||
shellResponse.message = "{\"success\": false}"; | ||
shellResponse.code = 22; | ||
when(mockTableManager.deleteBackup(any())).thenThrow(new RuntimeException("expected")); | ||
|
||
DeleteBackup deleteBackupTask = new DeleteBackup(); | ||
deleteBackupTask.initialize(params); | ||
deleteBackupTask.run(); | ||
|
||
verify(mockTableManager, times(1)).deleteBackup(any()); | ||
Backup backup = Backup.get(params.customerUUID, params.backupUUID); | ||
assertEquals(FailedToDelete, backup.state); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters