use of io.stackgres.common.extension.ExtensionManager.ExtensionUninstaller in project stackgres by ongres.
the class ExtensionReconciliationTest method testInitReconciliationWithExtensionPending_installIsPerformed.
@Test
void testInitReconciliationWithExtensionPending_installIsPerformed() throws Exception {
StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
ExtensionReconciliatorContext context = getContext(cluster -> {
cluster.getSpec().getPostgres().setExtensions(null);
cluster.getSpec().setToInstallPostgresExtensions(new ArrayList<>());
cluster.getSpec().getToInstallPostgresExtensions().add(installedExtension);
cluster.setStatus(new StackGresClusterStatus());
cluster.getStatus().setPodStatuses(new ArrayList<>());
StackGresClusterPodStatus podStatus = new StackGresClusterPodStatus();
podStatus.setName("test-0");
podStatus.setPendingRestart(true);
podStatus.setInstalledPostgresExtensions(new ArrayList<>());
podStatus.getInstalledPostgresExtensions().add(installedExtension);
cluster.getStatus().getPodStatuses().add(podStatus);
});
when(extensionManager.getExtensionInstaller(any(), any(StackGresClusterInstalledExtension.class))).thenReturn(extensionInstaller);
when(extensionInstaller.isExtensionInstalled()).thenReturn(false);
doNothing().when(eventEmitter).emitExtensionDeployed(installedExtension);
Assertions.assertTrue(initReconciliator.reconcile(null, context).result().get());
Assertions.assertTrue(Optional.of(context.getCluster()).map(StackGresCluster::getStatus).map(StackGresClusterStatus::getPodStatuses).stream().flatMap(List::stream).anyMatch(podStatus -> podStatus.getName().equals("test-0")));
Assertions.assertFalse(context.getCluster().getStatus().getPodStatuses().stream().filter(podStatus -> podStatus.getName().equals("test-0")).findAny().map(StackGresClusterPodStatus::getPendingRestart).orElse(false));
Assertions.assertIterableEquals(ImmutableList.of(installedExtension), context.getCluster().getStatus().getPodStatuses().stream().filter(podStatus -> podStatus.getName().equals("test-0")).findAny().map(StackGresClusterPodStatus::getInstalledPostgresExtensions).stream().flatMap(List::stream).collect(ImmutableList.toImmutableList()));
verify(extensionInstaller, times(1)).isExtensionInstalled();
verify(extensionInstaller, times(0)).isLinksCreated();
verify(extensionInstaller, times(0)).isExtensionPendingOverwrite();
verify(extensionUninstaller, times(0)).isExtensionInstalled();
verify(extensionInstaller, times(1)).downloadAndExtract();
verify(extensionInstaller, times(1)).verify();
verify(extensionInstaller, times(1)).installExtension();
verify(extensionInstaller, times(0)).createExtensionLinks();
verify(extensionInstaller, times(0)).doesInstallOverwriteAnySharedLibrary();
verify(extensionInstaller, times(0)).setExtensionAsPending();
verify(extensionUninstaller, times(0)).uninstallExtension();
verify(eventEmitter).emitExtensionDeployed(installedExtension);
}
use of io.stackgres.common.extension.ExtensionManager.ExtensionUninstaller in project stackgres by ongres.
the class ExtensionReconciliationTest method testReconciliationWithExtensionPending_installIsSkipped.
@Test
void testReconciliationWithExtensionPending_installIsSkipped() throws Exception {
StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
ExtensionReconciliatorContext context = getContext(cluster -> {
cluster.getSpec().getPostgres().setExtensions(null);
cluster.getSpec().setToInstallPostgresExtensions(new ArrayList<>());
cluster.getSpec().getToInstallPostgresExtensions().add(installedExtension);
cluster.setStatus(new StackGresClusterStatus());
cluster.getStatus().setPodStatuses(new ArrayList<>());
StackGresClusterPodStatus podStatus = new StackGresClusterPodStatus();
podStatus.setName("test-0");
podStatus.setPendingRestart(true);
podStatus.setInstalledPostgresExtensions(new ArrayList<>());
podStatus.getInstalledPostgresExtensions().add(installedExtension);
cluster.getStatus().getPodStatuses().add(podStatus);
});
when(extensionManager.getExtensionInstaller(any(), any(StackGresClusterInstalledExtension.class))).thenReturn(extensionInstaller);
when(extensionInstaller.isExtensionInstalled()).thenReturn(false);
when(extensionInstaller.isLinksCreated()).thenReturn(true);
when(extensionInstaller.isExtensionPendingOverwrite()).thenReturn(true);
Assertions.assertFalse(reconciliator.reconcile(null, context).result().get());
Assertions.assertTrue(Optional.of(context.getCluster()).map(StackGresCluster::getStatus).map(StackGresClusterStatus::getPodStatuses).stream().flatMap(List::stream).anyMatch(podStatus -> podStatus.getName().equals("test-0")));
Assertions.assertTrue(context.getCluster().getStatus().getPodStatuses().stream().filter(podStatus -> podStatus.getName().equals("test-0")).findAny().map(StackGresClusterPodStatus::getPendingRestart).orElse(false));
Assertions.assertIterableEquals(ImmutableList.of(installedExtension), context.getCluster().getStatus().getPodStatuses().stream().filter(podStatus -> podStatus.getName().equals("test-0")).findAny().map(StackGresClusterPodStatus::getInstalledPostgresExtensions).stream().flatMap(List::stream).collect(ImmutableList.toImmutableList()));
verify(extensionInstaller, times(1)).isExtensionInstalled();
verify(extensionInstaller, times(1)).isLinksCreated();
verify(extensionInstaller, times(1)).isExtensionPendingOverwrite();
verify(extensionUninstaller, times(0)).isExtensionInstalled();
verify(extensionInstaller, times(0)).downloadAndExtract();
verify(extensionInstaller, times(0)).verify();
verify(extensionInstaller, times(0)).installExtension();
verify(extensionInstaller, times(0)).createExtensionLinks();
verify(extensionInstaller, times(0)).doesInstallOverwriteAnySharedLibrary();
verify(extensionInstaller, times(0)).setExtensionAsPending();
verify(extensionUninstaller, times(0)).uninstallExtension();
}
use of io.stackgres.common.extension.ExtensionManager.ExtensionUninstaller in project stackgres by ongres.
the class ExtensionReconciliationTest method testReconciliationWithInstalledExtensions_uninstallIsSkippedButStatusUpdated.
@Test
void testReconciliationWithInstalledExtensions_uninstallIsSkippedButStatusUpdated() throws Exception {
final StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
ExtensionReconciliatorContext context = getContext(cluster -> {
cluster.getSpec().getPostgres().setExtensions(null);
cluster.setStatus(new StackGresClusterStatus());
cluster.getStatus().setPodStatuses(new ArrayList<>());
StackGresClusterPodStatus podStatus = new StackGresClusterPodStatus();
podStatus.setName("test-0");
podStatus.setInstalledPostgresExtensions(new ArrayList<>());
podStatus.getInstalledPostgresExtensions().add(installedExtension);
cluster.getStatus().getPodStatuses().add(podStatus);
});
Assertions.assertTrue(reconciliator.reconcile(null, context).result().get());
Assertions.assertTrue(Optional.of(context.getCluster()).map(StackGresCluster::getStatus).map(StackGresClusterStatus::getPodStatuses).stream().flatMap(List::stream).anyMatch(podStatus -> podStatus.getName().equals("test-0")));
Assertions.assertTrue(context.getCluster().getStatus().getPodStatuses().stream().filter(podStatus -> podStatus.getName().equals("test-0")).findAny().map(StackGresClusterPodStatus::getPendingRestart).orElse(true));
Assertions.assertIterableEquals(ImmutableList.of(installedExtension), context.getCluster().getStatus().getPodStatuses().stream().filter(podStatus -> podStatus.getName().equals("test-0")).findAny().map(StackGresClusterPodStatus::getInstalledPostgresExtensions).stream().flatMap(List::stream).collect(ImmutableList.toImmutableList()));
verify(extensionInstaller, times(0)).isExtensionInstalled();
verify(extensionInstaller, times(0)).isLinksCreated();
verify(extensionUninstaller, times(0)).isExtensionInstalled();
verify(extensionInstaller, times(0)).downloadAndExtract();
verify(extensionInstaller, times(0)).verify();
verify(extensionInstaller, times(0)).installExtension();
verify(extensionInstaller, times(0)).createExtensionLinks();
verify(extensionInstaller, times(0)).createExtensionLinks();
verify(extensionInstaller, times(0)).doesInstallOverwriteAnySharedLibrary();
verify(extensionInstaller, times(0)).setExtensionAsPending();
verify(extensionUninstaller, times(0)).uninstallExtension();
}
use of io.stackgres.common.extension.ExtensionManager.ExtensionUninstaller in project stackgres by ongres.
the class ExtensionReconciliationTest method testReconciliationWithExtensionThatOverwrite_installIsSkipped.
@Test
void testReconciliationWithExtensionThatOverwrite_installIsSkipped() throws Exception {
StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
when(extensionManager.getExtensionInstaller(any(), any(StackGresClusterInstalledExtension.class))).thenReturn(extensionInstaller);
when(extensionInstaller.isExtensionInstalled()).thenReturn(false);
when(extensionInstaller.isExtensionPendingOverwrite()).thenReturn(false);
when(extensionInstaller.doesInstallOverwriteAnySharedLibrary()).thenReturn(true);
ExtensionReconciliatorContext context = getContext(cluster -> {
cluster.getSpec().getPostgres().setExtensions(null);
cluster.getSpec().setToInstallPostgresExtensions(new ArrayList<>());
cluster.getSpec().getToInstallPostgresExtensions().add(installedExtension);
});
doNothing().when(eventEmitter).emitExtensionDeployedRestart(installedExtension);
Assertions.assertTrue(reconciliator.reconcile(null, context).result().get());
Assertions.assertTrue(Optional.of(context.getCluster()).map(StackGresCluster::getStatus).map(StackGresClusterStatus::getPodStatuses).stream().flatMap(List::stream).anyMatch(podStatus -> podStatus.getName().equals("test-0")));
Assertions.assertTrue(context.getCluster().getStatus().getPodStatuses().stream().filter(podStatus -> podStatus.getName().equals("test-0")).findAny().map(StackGresClusterPodStatus::getPendingRestart).orElse(false));
Assertions.assertIterableEquals(ImmutableList.of(installedExtension), context.getCluster().getStatus().getPodStatuses().stream().filter(podStatus -> podStatus.getName().equals("test-0")).findAny().map(StackGresClusterPodStatus::getInstalledPostgresExtensions).stream().flatMap(List::stream).collect(ImmutableList.toImmutableList()));
verify(extensionInstaller, times(1)).isExtensionInstalled();
verify(extensionInstaller, times(0)).isLinksCreated();
verify(extensionInstaller, times(2)).isExtensionPendingOverwrite();
verify(extensionUninstaller, times(0)).isExtensionInstalled();
verify(extensionInstaller, times(1)).downloadAndExtract();
verify(extensionInstaller, times(1)).verify();
verify(extensionInstaller, times(0)).installExtension();
verify(extensionInstaller, times(0)).createExtensionLinks();
verify(extensionInstaller, times(1)).doesInstallOverwriteAnySharedLibrary();
verify(extensionInstaller, times(1)).setExtensionAsPending();
verify(extensionUninstaller, times(0)).uninstallExtension();
verify(eventEmitter).emitExtensionDeployedRestart(installedExtension);
}
use of io.stackgres.common.extension.ExtensionManager.ExtensionUninstaller in project stackgres by ongres.
the class ExtensionReconciliationTest method testReconciliationWithPreviousExtensionAlreadyInstalled_upgradeIsPerformed.
@Test
void testReconciliationWithPreviousExtensionAlreadyInstalled_upgradeIsPerformed() throws Exception {
StackGresClusterInstalledExtension previousInstalledExtension = getInstalledExtension();
previousInstalledExtension.setVersion("1.7.0");
StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
ExtensionReconciliatorContext context = getContext(cluster -> {
cluster.getSpec().getPostgres().setExtensions(null);
cluster.getSpec().setToInstallPostgresExtensions(new ArrayList<>());
cluster.getSpec().getToInstallPostgresExtensions().add(installedExtension);
cluster.setStatus(new StackGresClusterStatus());
cluster.getStatus().setPodStatuses(new ArrayList<>());
StackGresClusterPodStatus podStatus = new StackGresClusterPodStatus();
podStatus.setName("test-0");
podStatus.setInstalledPostgresExtensions(new ArrayList<>());
podStatus.getInstalledPostgresExtensions().add(previousInstalledExtension);
cluster.getStatus().getPodStatuses().add(podStatus);
});
when(extensionManager.getExtensionInstaller(any(), any(StackGresClusterInstalledExtension.class))).thenReturn(extensionInstaller);
when(extensionInstaller.isExtensionPendingOverwrite()).thenReturn(false);
when(extensionInstaller.isExtensionInstalled()).thenReturn(false);
doNothing().when(eventEmitter).emitExtensionChanged(previousInstalledExtension, installedExtension);
Assertions.assertTrue(reconciliator.reconcile(null, context).result().get());
Assertions.assertTrue(Optional.of(context.getCluster()).map(StackGresCluster::getStatus).map(StackGresClusterStatus::getPodStatuses).stream().flatMap(List::stream).anyMatch(podStatus -> podStatus.getName().equals("test-0")));
Assertions.assertFalse(context.getCluster().getStatus().getPodStatuses().stream().filter(podStatus -> podStatus.getName().equals("test-0")).findAny().map(StackGresClusterPodStatus::getPendingRestart).orElse(false));
Assertions.assertIterableEquals(ImmutableList.of(installedExtension), context.getCluster().getStatus().getPodStatuses().stream().filter(podStatus -> podStatus.getName().equals("test-0")).findAny().map(StackGresClusterPodStatus::getInstalledPostgresExtensions).stream().flatMap(List::stream).collect(ImmutableList.toImmutableList()));
verify(extensionInstaller, times(1)).isExtensionInstalled();
verify(extensionInstaller, times(0)).isLinksCreated();
verify(extensionUninstaller, times(0)).isExtensionInstalled();
verify(extensionInstaller, times(1)).downloadAndExtract();
verify(extensionInstaller, times(1)).verify();
verify(extensionInstaller, times(1)).installExtension();
verify(extensionInstaller, times(0)).createExtensionLinks();
verify(extensionInstaller, times(1)).doesInstallOverwriteAnySharedLibrary();
verify(extensionInstaller, times(0)).setExtensionAsPending();
verify(extensionUninstaller, times(0)).uninstallExtension();
verify(eventEmitter).emitExtensionChanged(previousInstalledExtension, installedExtension);
}
Aggregations