Files
qbit-backups/src/test/java/com/kingsrook/qbits/backups/BackupsQBitProducerTest.java
T
james.maesandClaude Opus 5.5 b06c1fd8e4 feat(progress): report backup phases, counts, bytes and log lines as a durable job
Run backup now, restore and verify always run as durable jobs and report
their work through QQQ JobProgress: prepare, tables (N of M, bytes),
media (N of M, copied vs already stored) and upload phases, one log line
per table and artifact (keys relative to the run, never credentials or
row values), warnings and the failure. Restore and verify honour the job
page check for pause and cancel.

Needs QQQ 4.1.0-RC.8 (QRun-IO/qqq#1212).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 17:32:53 -05:00

105 lines
4.4 KiB
Java

/*
* Copyright 2026 Kingsrook, LLC
*
* Licensed 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 com.kingsrook.qbits.backups;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.qbits.QBitConfigValidationException;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/*******************************************************************************
** Unit test for BackupsQBitProducer
*******************************************************************************/
class BackupsQBitProducerTest
{
/*******************************************************************************
** A configured qbit registers itself in the instance.
*******************************************************************************/
@Test
void testProduce() throws Exception
{
QInstance qInstance = new QInstance();
BackupsQBitConfig config = new BackupsQBitConfig().withBackendName("rdbms");
BackupsQBitProducer producer = new BackupsQBitProducer().withQBitConfig(config).withNamespace("backups");
assertThat(producer.isEnabled()).isTrue();
assertThat(producer.getQBitConfig()).isSameAs(config);
assertThat(producer.getNamespace()).isEqualTo("backups");
assertThat(config.getDefaultBackendNameForTables()).isEqualTo("rdbms");
producer.produce(qInstance);
assertThat(qInstance.getQBits()).hasSize(1);
assertThat(qInstance.getQBits().values().iterator().next().getArtifactId()).isEqualTo("qbit-backups");
}
/*******************************************************************************
** Without a config the producer is disabled; without a backend it fails.
*******************************************************************************/
@Test
void testDisabledAndInvalid()
{
assertThat(new BackupsQBitProducer().isEnabled()).isFalse();
BackupsQBitConfig config = new BackupsQBitConfig();
config.setBackendName(null);
assertThat(config.getBackendName()).isNull();
assertThatThrownBy(() -> new BackupsQBitProducer().withQBitConfig(config).produce(new QInstance()))
.isInstanceOf(QBitConfigValidationException.class);
}
/*******************************************************************************
** Names follow the owner rule: lowercase snake_case with the full qbit name.
*******************************************************************************/
@Test
void testNaming()
{
assertThat(BackupsQBitConfig.TABLE_NAME_PREFIX).isEqualTo("backups_").matches("^[a-z][a-z0-9_]*_$");
assertThat(BackupsQBitConfig.PERMISSION_BASE_NAME).isEqualTo("backups");
}
/*******************************************************************************
** Long operations always enqueue, with no unsafe automatic external replay.
*******************************************************************************/
@Test
void testDurableProcesses() throws Exception
{
BackupsTestUtils.init();
for(String name : java.util.List.of("backupRunPlan", "backupRunScheduledPlan", "backupResumeRun", "backupRestore", "backupRestoreTable", "backupVerify"))
{
var process = com.kingsrook.qqq.backend.core.context.QContext.getQInstance().getProcess(name);
assertThat(process).as(name).isNotNull();
var durability = com.kingsrook.qqq.backend.core.jobs.DurableProcessMetaData.of(process);
assertThat(durability).as(name).isNotNull();
assertThat(durability.getAlwaysDurable()).isTrue();
assertThat(durability.getEligible()).isTrue();
assertThat(durability.getIdempotency()).isEqualTo(com.kingsrook.qqq.backend.core.jobs.model.JobIdempotency.NONE);
assertThat(durability.getChunkSize()).isEqualTo(1);
}
}
}