Search in sources :

Example 1 with ClusterLogEntryDto

use of io.stackgres.apiweb.dto.cluster.ClusterLogEntryDto in project stackgres by ongres.

the class ClusterResourceMockedTest method getLogsWithAscSortShouldNotFail.

@Test
void getLogsWithAscSortShouldNotFail() {
    clusterMocks();
    when(finder.findByNameAndNamespace(getResourceName(), getResourceNamespace())).thenReturn(Optional.of(customResources.getItems().get(0)));
    doAnswer(new Answer<List<ClusterLogEntryDto>>() {

        @Override
        public List<ClusterLogEntryDto> answer(InvocationOnMock invocation) throws Throwable {
            DistributedLogsQueryParameters parameters = invocation.getArgument(0);
            assertNotNull(parameters);
            checkDto(parameters.getCluster(), customResources.getItems().get(0));
            assertEquals(50, parameters.getRecords());
            assertEquals(Optional.empty(), parameters.getFromTimeAndIndex());
            assertEquals(Optional.empty(), parameters.getToTimeAndIndex());
            assertEquals(parameters.getFilters(), ImmutableMap.of());
            assertEquals(parameters.getFullTextSearchQuery(), Optional.empty());
            assertTrue(parameters.isSortAsc());
            assertFalse(parameters.isFromInclusive());
            return logList;
        }
    }).when(distributedLogsFetcher).logs(any());
    Integer records = null;
    String from = null;
    String to = null;
    String sort = "asc";
    String text = null;
    List<String> logType = null;
    List<String> podName = null;
    List<String> role = null;
    List<String> errorLevel = null;
    List<String> userName = null;
    List<String> databaseName = null;
    Boolean fromInclusive = null;
    List<ClusterLogEntryDto> logs = getClusterLogsResource().logs(getResourceNamespace(), getResourceName(), records, from, to, sort, text, logType, podName, role, errorLevel, userName, databaseName, fromInclusive);
    assertIterableEquals(logList, logs);
}
Also used : ClusterLogEntryDto(io.stackgres.apiweb.dto.cluster.ClusterLogEntryDto) DistributedLogsQueryParameters(io.stackgres.apiweb.distributedlogs.DistributedLogsQueryParameters) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CustomResourceList(io.fabric8.kubernetes.client.CustomResourceList) ArrayList(java.util.ArrayList) PodList(io.fabric8.kubernetes.api.model.PodList) List(java.util.List) StackGresClusterList(io.stackgres.common.crd.sgcluster.StackGresClusterList) ImmutableList(com.google.common.collect.ImmutableList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 2 with ClusterLogEntryDto

use of io.stackgres.apiweb.dto.cluster.ClusterLogEntryDto in project stackgres by ongres.

the class ClusterResourceMockedTest method getLogsWithToAndIndexShouldNotFail.

@Test
void getLogsWithToAndIndexShouldNotFail() {
    clusterMocks();
    when(finder.findByNameAndNamespace(getResourceName(), getResourceNamespace())).thenReturn(Optional.of(customResources.getItems().get(0)));
    doAnswer(new Answer<List<ClusterLogEntryDto>>() {

        @Override
        public List<ClusterLogEntryDto> answer(InvocationOnMock invocation) throws Throwable {
            DistributedLogsQueryParameters parameters = invocation.getArgument(0);
            assertNotNull(parameters);
            checkDto(parameters.getCluster(), customResources.getItems().get(0));
            assertEquals(50, parameters.getRecords());
            assertEquals(Optional.empty(), parameters.getFromTimeAndIndex());
            assertEquals(Optional.of(Tuple.tuple(Instant.EPOCH, 1)), parameters.getToTimeAndIndex());
            assertEquals(parameters.getFilters(), ImmutableMap.of());
            assertEquals(parameters.getFullTextSearchQuery(), Optional.empty());
            assertFalse(parameters.isSortAsc());
            assertFalse(parameters.isFromInclusive());
            return logList;
        }
    }).when(distributedLogsFetcher).logs(any());
    Integer records = null;
    String from = null;
    String to = Instant.EPOCH.toString() + "," + 1;
    String sort = null;
    String text = null;
    List<String> logType = null;
    List<String> podName = null;
    List<String> role = null;
    List<String> errorLevel = null;
    List<String> userName = null;
    List<String> databaseName = null;
    Boolean fromInclusive = null;
    List<ClusterLogEntryDto> logs = getClusterLogsResource().logs(getResourceNamespace(), getResourceName(), records, from, to, sort, text, logType, podName, role, errorLevel, userName, databaseName, fromInclusive);
    assertIterableEquals(logList, logs);
}
Also used : ClusterLogEntryDto(io.stackgres.apiweb.dto.cluster.ClusterLogEntryDto) DistributedLogsQueryParameters(io.stackgres.apiweb.distributedlogs.DistributedLogsQueryParameters) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CustomResourceList(io.fabric8.kubernetes.client.CustomResourceList) ArrayList(java.util.ArrayList) PodList(io.fabric8.kubernetes.api.model.PodList) List(java.util.List) StackGresClusterList(io.stackgres.common.crd.sgcluster.StackGresClusterList) ImmutableList(com.google.common.collect.ImmutableList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 3 with ClusterLogEntryDto

use of io.stackgres.apiweb.dto.cluster.ClusterLogEntryDto in project stackgres by ongres.

the class ClusterResourceMockedTest method getLogsWithRoleFilterShouldNotFail.

@Test
void getLogsWithRoleFilterShouldNotFail() {
    clusterMocks();
    when(finder.findByNameAndNamespace(getResourceName(), getResourceNamespace())).thenReturn(Optional.of(customResources.getItems().get(0)));
    doAnswer(new Answer<List<ClusterLogEntryDto>>() {

        @Override
        public List<ClusterLogEntryDto> answer(InvocationOnMock invocation) throws Throwable {
            DistributedLogsQueryParameters parameters = invocation.getArgument(0);
            assertNotNull(parameters);
            checkDto(parameters.getCluster(), customResources.getItems().get(0));
            assertEquals(50, parameters.getRecords());
            assertEquals(Optional.empty(), parameters.getFromTimeAndIndex());
            assertEquals(Optional.empty(), parameters.getToTimeAndIndex());
            assertEquals(parameters.getFilters(), ImmutableMap.of("role", List.of("test")));
            assertEquals(parameters.getFullTextSearchQuery(), Optional.empty());
            assertFalse(parameters.isSortAsc());
            assertFalse(parameters.isFromInclusive());
            return logList;
        }
    }).when(distributedLogsFetcher).logs(any());
    Integer records = null;
    String from = null;
    String to = null;
    String sort = null;
    String text = null;
    List<String> logType = null;
    List<String> podName = null;
    List<String> role = List.of("test");
    List<String> errorLevel = null;
    List<String> userName = null;
    List<String> databaseName = null;
    Boolean fromInclusive = null;
    List<ClusterLogEntryDto> logs = getClusterLogsResource().logs(getResourceNamespace(), getResourceName(), records, from, to, sort, text, logType, podName, role, errorLevel, userName, databaseName, fromInclusive);
    assertIterableEquals(logList, logs);
}
Also used : ClusterLogEntryDto(io.stackgres.apiweb.dto.cluster.ClusterLogEntryDto) DistributedLogsQueryParameters(io.stackgres.apiweb.distributedlogs.DistributedLogsQueryParameters) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CustomResourceList(io.fabric8.kubernetes.client.CustomResourceList) ArrayList(java.util.ArrayList) PodList(io.fabric8.kubernetes.api.model.PodList) List(java.util.List) StackGresClusterList(io.stackgres.common.crd.sgcluster.StackGresClusterList) ImmutableList(com.google.common.collect.ImmutableList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 4 with ClusterLogEntryDto

use of io.stackgres.apiweb.dto.cluster.ClusterLogEntryDto in project stackgres by ongres.

the class ClusterResourceMockedTest method getLogsWithFromShouldNotFail.

@Test
void getLogsWithFromShouldNotFail() {
    clusterMocks();
    when(finder.findByNameAndNamespace(getResourceName(), getResourceNamespace())).thenReturn(Optional.of(customResources.getItems().get(0)));
    doAnswer(new Answer<List<ClusterLogEntryDto>>() {

        @Override
        public List<ClusterLogEntryDto> answer(InvocationOnMock invocation) throws Throwable {
            DistributedLogsQueryParameters parameters = invocation.getArgument(0);
            assertNotNull(parameters);
            checkDto(parameters.getCluster(), customResources.getItems().get(0));
            assertEquals(50, parameters.getRecords());
            assertEquals(Optional.of(Tuple.tuple(Instant.EPOCH, 0)), parameters.getFromTimeAndIndex());
            assertEquals(Optional.empty(), parameters.getToTimeAndIndex());
            assertEquals(ImmutableMap.of(), parameters.getFilters());
            assertEquals(Optional.empty(), parameters.getFullTextSearchQuery());
            assertFalse(parameters.isSortAsc());
            assertFalse(parameters.isFromInclusive());
            return logList;
        }
    }).when(distributedLogsFetcher).logs(any());
    Integer records = null;
    String from = Instant.EPOCH.toString();
    String to = null;
    String sort = null;
    String text = null;
    List<String> logType = null;
    List<String> podName = null;
    List<String> role = null;
    List<String> errorLevel = null;
    List<String> userName = null;
    List<String> databaseName = null;
    Boolean fromInclusive = null;
    List<ClusterLogEntryDto> logs = getClusterLogsResource().logs(getResourceNamespace(), getResourceName(), records, from, to, sort, text, logType, podName, role, errorLevel, userName, databaseName, fromInclusive);
    assertIterableEquals(logList, logs);
}
Also used : ClusterLogEntryDto(io.stackgres.apiweb.dto.cluster.ClusterLogEntryDto) DistributedLogsQueryParameters(io.stackgres.apiweb.distributedlogs.DistributedLogsQueryParameters) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CustomResourceList(io.fabric8.kubernetes.client.CustomResourceList) ArrayList(java.util.ArrayList) PodList(io.fabric8.kubernetes.api.model.PodList) List(java.util.List) StackGresClusterList(io.stackgres.common.crd.sgcluster.StackGresClusterList) ImmutableList(com.google.common.collect.ImmutableList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 5 with ClusterLogEntryDto

use of io.stackgres.apiweb.dto.cluster.ClusterLogEntryDto in project stackgres by ongres.

the class ClusterResourceMockedTest method getLogsWithErrorLevelFilterShouldNotFail.

@Test
void getLogsWithErrorLevelFilterShouldNotFail() {
    clusterMocks();
    when(finder.findByNameAndNamespace(getResourceName(), getResourceNamespace())).thenReturn(Optional.of(customResources.getItems().get(0)));
    doAnswer(new Answer<List<ClusterLogEntryDto>>() {

        @Override
        public List<ClusterLogEntryDto> answer(InvocationOnMock invocation) throws Throwable {
            DistributedLogsQueryParameters parameters = invocation.getArgument(0);
            assertNotNull(parameters);
            checkDto(parameters.getCluster(), customResources.getItems().get(0));
            assertEquals(50, parameters.getRecords());
            assertEquals(Optional.empty(), parameters.getFromTimeAndIndex());
            assertEquals(Optional.empty(), parameters.getToTimeAndIndex());
            assertEquals(parameters.getFilters(), ImmutableMap.of("errorLevel", List.of("test")));
            assertEquals(parameters.getFullTextSearchQuery(), Optional.empty());
            assertFalse(parameters.isSortAsc());
            assertFalse(parameters.isFromInclusive());
            return logList;
        }
    }).when(distributedLogsFetcher).logs(any());
    Integer records = null;
    String from = null;
    String to = null;
    String sort = null;
    String text = null;
    List<String> logType = null;
    List<String> podName = null;
    List<String> role = null;
    List<String> errorLevel = List.of("test");
    List<String> userName = null;
    List<String> databaseName = null;
    Boolean fromInclusive = null;
    List<ClusterLogEntryDto> logs = getClusterLogsResource().logs(getResourceNamespace(), getResourceName(), records, from, to, sort, text, logType, podName, role, errorLevel, userName, databaseName, fromInclusive);
    assertIterableEquals(logList, logs);
}
Also used : ClusterLogEntryDto(io.stackgres.apiweb.dto.cluster.ClusterLogEntryDto) DistributedLogsQueryParameters(io.stackgres.apiweb.distributedlogs.DistributedLogsQueryParameters) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CustomResourceList(io.fabric8.kubernetes.client.CustomResourceList) ArrayList(java.util.ArrayList) PodList(io.fabric8.kubernetes.api.model.PodList) List(java.util.List) StackGresClusterList(io.stackgres.common.crd.sgcluster.StackGresClusterList) ImmutableList(com.google.common.collect.ImmutableList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)26 ClusterLogEntryDto (io.stackgres.apiweb.dto.cluster.ClusterLogEntryDto)26 List (java.util.List)26 DistributedLogsQueryParameters (io.stackgres.apiweb.distributedlogs.DistributedLogsQueryParameters)25 PodList (io.fabric8.kubernetes.api.model.PodList)24 CustomResourceList (io.fabric8.kubernetes.client.CustomResourceList)24 StackGresClusterList (io.stackgres.common.crd.sgcluster.StackGresClusterList)24 ArrayList (java.util.ArrayList)24 Test (org.junit.jupiter.api.Test)24 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)24 InvocationOnMock (org.mockito.invocation.InvocationOnMock)24 FullTextSearchQuery (io.stackgres.apiweb.distributedlogs.FullTextSearchQuery)5 ClusterDto (io.stackgres.apiweb.dto.cluster.ClusterDto)4 ClusterSpec (io.stackgres.apiweb.dto.cluster.ClusterSpec)4 Optional (java.util.Optional)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Secret (io.fabric8.kubernetes.api.model.Secret)3 DistributedLogsFetcher (io.stackgres.apiweb.distributedlogs.DistributedLogsFetcher)3 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)2