use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class ExtensionManagerTest method testVerifyExtension.
@Test
void testVerifyExtension() throws Exception {
StackGresCluster cluster = getCluster();
StackGresClusterInstalledExtension extension = getInstalledExtension();
when(webClientFactory.create(anyBoolean())).thenReturn(webClient);
when(webClient.getJson(any(), any())).thenReturn(getExtensions());
final String extensionPackageName = ExtensionUtil.getExtensionPackageName(getInstalledExtension());
when(fileSystemHandler.newInputStream(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve(extensionPackageName + ExtensionManager.SHA256_SUFFIX)))).then(invocation -> getClass().getResourceAsStream("/test.tgz.sha256"));
when(fileSystemHandler.newInputStream(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve(extensionPackageName + ExtensionManager.TGZ_SUFFIX)))).then(invocation -> getClass().getResourceAsStream("/test.tgz"));
extensionManager.getExtensionInstaller(context(cluster), extension).verify();
;
verify(webClientFactory, times(1)).create(anyBoolean());
verify(webClient, times(1)).getJson(any(), any());
verify(webClient, times(1)).getJson(eq(ExtensionUtil.getIndexUri(REPOSITORY)), eq(StackGresExtensions.class));
verify(webClient, times(0)).getInputStream(eq(ExtensionUtil.getExtensionPackageUri(REPOSITORY, extension, getExtensionMetadata())));
verify(fileSystemHandler, times(2)).newInputStream(any());
verify(fileSystemHandler, times(1)).newInputStream(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve(extensionPackageName + ExtensionManager.SHA256_SUFFIX)));
verify(fileSystemHandler, times(1)).newInputStream(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve(extensionPackageName + ExtensionManager.TGZ_SUFFIX)));
verify(fileSystemHandler, times(0)).createOrReplaceFile(any());
verify(fileSystemHandler, times(0)).createDirectories(any());
verify(fileSystemHandler, times(0)).createOrReplaceSymbolicLink(any(), any());
verify(fileSystemHandler, times(0)).copyOrReplace(any(), any());
verify(fileSystemHandler, times(0)).setPosixFilePermissions(any(), any());
verify(fileSystemHandler, times(0)).deleteIfExists(any());
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class ExtensionManagerTest method testInstallExtension.
@Test
void testInstallExtension() throws Exception {
StackGresCluster cluster = getCluster();
StackGresClusterInstalledExtension extension = getInstalledExtension();
when(webClientFactory.create(anyBoolean())).thenReturn(webClient);
when(webClient.getJson(any(), any())).thenReturn(getExtensions());
final String extensionPackageName = ExtensionUtil.getExtensionPackageName(getInstalledExtension());
when(fileSystemHandler.newInputStream(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve(extensionPackageName + ExtensionManager.TGZ_SUFFIX)))).then(invocation -> getClass().getResourceAsStream("/test.tgz"));
when(fileSystemHandler.list(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_LIB_PATH.path(context(cluster)))))).thenReturn(Stream.of(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_LIB_PATH.path(context(cluster))).resolve("test.so")));
ExtensionInstaller extensionInstaller = extensionManager.getExtensionInstaller(context(cluster), extension);
extensionInstaller.installExtension();
verify(webClientFactory, times(1)).create(anyBoolean());
verify(webClient, times(1)).getJson(any(), any());
verify(webClient, times(1)).getJson(eq(ExtensionUtil.getIndexUri(REPOSITORY)), eq(StackGresExtensions.class));
verify(webClient, times(0)).getInputStream(any());
verify(fileSystemHandler, times(1)).newInputStream(any());
verify(fileSystemHandler, times(1)).newInputStream(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve(extensionPackageName + ExtensionManager.TGZ_SUFFIX)));
verify(fileSystemHandler, times(2)).createOrReplaceFile(any());
verify(fileSystemHandler, times(1)).createOrReplaceFile(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve(extensionPackageName + ExtensionManager.INSTALLED_SUFFIX)));
verify(fileSystemHandler, times(1)).createOrReplaceFile(eq(Paths.get(ClusterStatefulSetPath.PG_RELOCATED_LIB_PATH.path(context(cluster))).resolve(extensionPackageName + ExtensionManager.LINKS_CREATED_SUFFIX)));
verify(fileSystemHandler, times(17)).createDirectories(any());
verify(fileSystemHandler, times(1)).createDirectories(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr")));
verify(fileSystemHandler, times(1)).createDirectories(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/lib")));
verify(fileSystemHandler, times(1)).createDirectories(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/lib/postgresql")));
verify(fileSystemHandler, times(1)).createDirectories(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/lib/postgresql/12")));
verify(fileSystemHandler, times(2)).createDirectories(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/lib/postgresql/12/lib")));
verify(fileSystemHandler, times(1)).createDirectories(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/lib/postgresql/12/bin")));
verify(fileSystemHandler, times(4)).createDirectories(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_LIB64_PATH.path(context(cluster)))));
verify(fileSystemHandler, times(1)).createDirectories(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/share")));
verify(fileSystemHandler, times(1)).createDirectories(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/share/postgresql")));
verify(fileSystemHandler, times(1)).createDirectories(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/share/postgresql/12")));
verify(fileSystemHandler, times(3)).createDirectories(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/share/postgresql/12/extension")));
verify(fileSystemHandler, times(3)).createOrReplaceSymbolicLink(any(), any());
verify(fileSystemHandler, times(1)).createOrReplaceSymbolicLink(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_LIB64_PATH.path(context(cluster))).resolve("test.so.1")), eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_LIB64_PATH.path(context(cluster))).resolve("test.so.1.0")));
verify(fileSystemHandler, times(1)).createOrReplaceSymbolicLink(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_LIB64_PATH.path(context(cluster))).resolve("test.so.2")), eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_LIB64_PATH.path(context(cluster))).resolve("test.so.2.0")));
verify(fileSystemHandler, times(1)).createOrReplaceSymbolicLink(eq(Paths.get(ClusterStatefulSetPath.PG_RELOCATED_LIB_PATH.path(context(cluster))).resolve("test.so")), eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_LIB_PATH.path(context(cluster))).resolve("test.so")));
verify(fileSystemHandler, times(4)).copyOrReplace(any(), any());
verify(fileSystemHandler, times(1)).copyOrReplace(any(), eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/lib/postgresql/12/lib").resolve("test.so")));
verify(fileSystemHandler, times(1)).copyOrReplace(any(), eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/share/postgresql/12/extension").resolve("test.control")));
verify(fileSystemHandler, times(1)).copyOrReplace(any(), eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/share/postgresql/12/extension").resolve("test.sql")));
verify(fileSystemHandler, times(1)).copyOrReplace(any(), eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_LIB64_PATH.path(context(cluster))).resolve("test.so.1.0")));
verify(fileSystemHandler, times(15)).setPosixFilePermissions(any(), any());
verify(fileSystemHandler, times(1)).setPosixFilePermissions(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr")), eq(ImmutableSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_READ, PosixFilePermission.GROUP_EXECUTE, PosixFilePermission.OTHERS_READ, PosixFilePermission.OTHERS_EXECUTE)));
verify(fileSystemHandler, times(1)).setPosixFilePermissions(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/lib")), eq(ImmutableSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_READ, PosixFilePermission.GROUP_EXECUTE, PosixFilePermission.OTHERS_READ, PosixFilePermission.OTHERS_EXECUTE)));
verify(fileSystemHandler, times(1)).setPosixFilePermissions(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/lib/postgresql")), eq(ImmutableSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_READ, PosixFilePermission.GROUP_EXECUTE, PosixFilePermission.OTHERS_READ, PosixFilePermission.OTHERS_EXECUTE)));
verify(fileSystemHandler, times(1)).setPosixFilePermissions(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/lib/postgresql/12")), eq(ImmutableSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_READ, PosixFilePermission.GROUP_EXECUTE, PosixFilePermission.OTHERS_READ, PosixFilePermission.OTHERS_EXECUTE)));
verify(fileSystemHandler, times(1)).setPosixFilePermissions(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/lib/postgresql/12/lib")), eq(ImmutableSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_READ, PosixFilePermission.GROUP_EXECUTE, PosixFilePermission.OTHERS_READ, PosixFilePermission.OTHERS_EXECUTE)));
verify(fileSystemHandler, times(1)).setPosixFilePermissions(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/lib/postgresql/12/bin")), eq(ImmutableSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_READ, PosixFilePermission.GROUP_EXECUTE, PosixFilePermission.OTHERS_READ, PosixFilePermission.OTHERS_EXECUTE)));
verify(fileSystemHandler, times(1)).setPosixFilePermissions(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_LIB64_PATH.path(context(cluster)))), eq(ImmutableSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_READ, PosixFilePermission.GROUP_EXECUTE, PosixFilePermission.OTHERS_READ, PosixFilePermission.OTHERS_EXECUTE)));
verify(fileSystemHandler, times(1)).setPosixFilePermissions(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/share")), eq(ImmutableSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_READ, PosixFilePermission.GROUP_EXECUTE, PosixFilePermission.OTHERS_READ, PosixFilePermission.OTHERS_EXECUTE)));
verify(fileSystemHandler, times(1)).setPosixFilePermissions(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/share/postgresql")), eq(ImmutableSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_READ, PosixFilePermission.GROUP_EXECUTE, PosixFilePermission.OTHERS_READ, PosixFilePermission.OTHERS_EXECUTE)));
verify(fileSystemHandler, times(1)).setPosixFilePermissions(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/share/postgresql/12")), eq(ImmutableSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_READ, PosixFilePermission.GROUP_EXECUTE, PosixFilePermission.OTHERS_READ, PosixFilePermission.OTHERS_EXECUTE)));
verify(fileSystemHandler, times(1)).setPosixFilePermissions(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/share/postgresql/12/extension")), eq(ImmutableSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_READ, PosixFilePermission.GROUP_EXECUTE, PosixFilePermission.OTHERS_READ, PosixFilePermission.OTHERS_EXECUTE)));
verify(fileSystemHandler, times(1)).setPosixFilePermissions(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/lib/postgresql/12/lib").resolve("test.so")), eq(ImmutableSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.GROUP_READ, PosixFilePermission.OTHERS_READ)));
verify(fileSystemHandler, times(1)).setPosixFilePermissions(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/share/postgresql/12/extension").resolve("test.control")), eq(ImmutableSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.GROUP_READ, PosixFilePermission.OTHERS_READ)));
verify(fileSystemHandler, times(1)).setPosixFilePermissions(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve("usr/share/postgresql/12/extension").resolve("test.sql")), eq(ImmutableSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.GROUP_READ, PosixFilePermission.OTHERS_READ)));
verify(fileSystemHandler, times(1)).setPosixFilePermissions(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_LIB64_PATH.path(context(cluster))).resolve("test.so.1.0")), eq(ImmutableSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.GROUP_READ, PosixFilePermission.OTHERS_READ)));
verify(fileSystemHandler, times(1)).deleteIfExists(any());
verify(fileSystemHandler, times(1)).deleteIfExists(eq(Paths.get(ClusterStatefulSetPath.PG_EXTENSIONS_PATH.path(context(cluster))).resolve(extensionPackageName + ExtensionManager.PENDING_SUFFIX)));
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class ExtensionReconciliationTest method testInitReconciliationWithInstalledExtensions_uninstallIsPerformed.
@Test
void testInitReconciliationWithInstalledExtensions_uninstallIsPerformed() throws Exception {
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);
});
when(extensionManager.getExtensionUninstaller(any(), any(StackGresClusterInstalledExtension.class))).thenReturn(extensionUninstaller);
when(extensionUninstaller.isExtensionInstalled()).thenReturn(true);
doNothing().when(eventEmitter).emitExtensionRemoved(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(), 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(1)).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(1)).uninstallExtension();
verify(eventEmitter).emitExtensionRemoved(installedExtension);
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class ExtensionReconciliationTest method testReconciliationWithExtAlreadyPresentButLinksNotCreated_installIsSkippedButLinksCreated.
@Test
void testReconciliationWithExtAlreadyPresentButLinksNotCreated_installIsSkippedButLinksCreated() 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.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(true);
when(extensionInstaller.isLinksCreated()).thenReturn(false);
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.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(1)).isLinksCreated();
verify(extensionUninstaller, times(0)).isExtensionInstalled();
verify(extensionInstaller, times(0)).downloadAndExtract();
verify(extensionInstaller, times(0)).verify();
verify(extensionInstaller, times(0)).installExtension();
verify(extensionInstaller, times(1)).createExtensionLinks();
verify(extensionInstaller, times(0)).doesInstallOverwriteAnySharedLibrary();
verify(extensionInstaller, times(0)).setExtensionAsPending();
verify(extensionUninstaller, times(0)).uninstallExtension();
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class ExtensionReconciliationTest method testInitReconciliationWithExtensionThatOverwrite_installIsPerformed.
@Test
void testInitReconciliationWithExtensionThatOverwrite_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);
});
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);
}
Aggregations