diff --git a/alarm-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/alarm/datastore/cassandra/AlarmDatastoreCassandra.java b/alarm-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/alarm/datastore/cassandra/AlarmDatastoreCassandra.java index d2a2b7b1..9bb3ec47 100644 --- a/alarm-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/alarm/datastore/cassandra/AlarmDatastoreCassandra.java +++ b/alarm-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/alarm/datastore/cassandra/AlarmDatastoreCassandra.java @@ -782,6 +782,15 @@ public class AlarmDatastoreCassandra implements AlarmDatastore { // startAfterItem is not used in Cassandra datastores, set it to null ret.getContext().setStartAfterItem(null); + //in cassandra we will rely only on nextPagingState to set the lastPage indicator + ret.getContext().setLastPage(false); + + if(nextPagingState == null) { + //in cassandra, if there are no more pages available, the pagingState is returned as null by the driver + //this overrides all other heuristics related to guessing the indication of the last page + ret.getContext().setLastPage(true); + } + return ret; } diff --git a/alarm-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/alarm/datastore/cassandra/AlarmDatastoreCassandraTests.java b/alarm-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/alarm/datastore/cassandra/AlarmDatastoreCassandraTests.java index c208a864..8f6ec4e3 100644 --- a/alarm-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/alarm/datastore/cassandra/AlarmDatastoreCassandraTests.java +++ b/alarm-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/alarm/datastore/cassandra/AlarmDatastoreCassandraTests.java @@ -1,18 +1,9 @@ package com.telecominfraproject.wlan.alarm.datastore.cassandra; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; import org.junit.Ignore; -import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -20,12 +11,6 @@ import org.springframework.context.annotation.Import; import org.springframework.test.context.junit4.SpringRunner; import com.telecominfraproject.wlan.alarm.datastore.BaseAlarmDatastoreTest; -import com.telecominfraproject.wlan.alarm.models.Alarm; -import com.telecominfraproject.wlan.alarm.models.AlarmCode; -import com.telecominfraproject.wlan.core.model.pagination.ColumnAndSort; -import com.telecominfraproject.wlan.core.model.pagination.PaginationContext; -import com.telecominfraproject.wlan.core.model.pagination.PaginationResponse; -import com.telecominfraproject.wlan.core.model.pagination.SortOrder; import com.telecominfraproject.wlan.core.server.cassandra.BaseCassandraDataSource; import com.telecominfraproject.wlan.core.server.cassandra.test.BaseCassandraTest; @@ -40,181 +25,21 @@ import com.telecominfraproject.wlan.core.server.cassandra.test.BaseCassandraTest @Ignore("Ignore Cassandra Tests until we can set up a cassandra cluster for the integration testing") public class AlarmDatastoreCassandraTests extends BaseAlarmDatastoreTest { - @Test @Override - //Cassandra has some limitations for sorting and filtering vs other data store types, - // that's why this method is adjusted for cassandra datastore specifically - public void testAlarmPagination() - { - //create 100 Alarms - Alarm mdl; - int customerId_1 = (int) testSequence.incrementAndGet(); - int customerId_2 = (int) testSequence.incrementAndGet(); - - int apNameIdx = 0; - Set equipmentIds = new HashSet<>(); - Set alarmCodes = new HashSet<>(Arrays.asList(AlarmCode.AccessPointIsUnreachable, AlarmCode.AssocFailure)); - long pastTimestamp = 0; - Set equipmentIds_c2 = new HashSet<>(); - - testInterface.resetAlarmCounters(); - - for(int i = 0; i< 50; i++){ - mdl = createAlarmObject(); - mdl.setCustomerId(customerId_1); - mdl.setScopeId("qr_"+apNameIdx); - equipmentIds.add(mdl.getEquipmentId()); - - if(i == 8) { - //create one record for the time of 10 sec ago - mdl.setCreatedTimestamp(mdl.getCreatedTimestamp() - 10000); - pastTimestamp = mdl.getCreatedTimestamp(); - } - - apNameIdx++; - testInterface.create(mdl); - } - - testInterface.resetAlarmCounters(); - - for(int i = 0; i< 50; i++){ - mdl = createAlarmObject(); - mdl.setCustomerId(customerId_2); - mdl.setScopeId("qr_"+apNameIdx); - equipmentIds_c2.add(mdl.getEquipmentId()); - apNameIdx++; - testInterface.create(mdl); - } - - //paginate over Alarms - - List sortBy = new ArrayList<>(); - //In Cassandra the support for pagination order is very limited fixed at table creation, supplied sortBy options will be ignored. - //sortBy.addAll(Arrays.asList(new ColumnAndSort("equipmentId"))); - - //get active alarms for all equipment and all alarmCodes for the customer since the beginning of time - PaginationContext context = new PaginationContext<>(10); - PaginationResponse page1 = null; - PaginationResponse page2 = null; - PaginationResponse page3 = null; - PaginationResponse page4 = null; - PaginationResponse page5 = null; - PaginationResponse page6 = null; - PaginationResponse page7 = null; - - - page1 = testInterface.getForCustomer(customerId_1, null, null, -1, sortBy, context); - page2 = testInterface.getForCustomer(customerId_1, null, null, -1, sortBy, page1.getContext()); - page3 = testInterface.getForCustomer(customerId_1, null, null, -1, sortBy, page2.getContext()); - page4 = testInterface.getForCustomer(customerId_1, null, null, -1, sortBy, page3.getContext()); - page5 = testInterface.getForCustomer(customerId_1, null, null, -1, sortBy, page4.getContext()); - page6 = testInterface.getForCustomer(customerId_1, null, null, -1, sortBy, page5.getContext()); - page7 = testInterface.getForCustomer(customerId_1, null, null, -1, sortBy, page6.getContext()); - - //verify returned pages - assertEquals(10, page1.getItems().size()); - assertEquals(10, page2.getItems().size()); - assertEquals(10, page3.getItems().size()); - assertEquals(10, page4.getItems().size()); - assertEquals(10, page5.getItems().size()); - - page1.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page2.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page3.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page4.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page5.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - - assertEquals(0, page6.getItems().size()); - assertEquals(0, page7.getItems().size()); - - assertFalse(page1.getContext().isLastPage()); - assertFalse(page2.getContext().isLastPage()); - assertFalse(page3.getContext().isLastPage()); - assertFalse(page4.getContext().isLastPage()); - assertFalse(page5.getContext().isLastPage()); - - assertTrue(page6.getContext().isLastPage()); - assertTrue(page7.getContext().isLastPage()); - - //the order is weird, but consistent - List expectedPage3Strings = new ArrayList< >(Arrays.asList(new String[]{"qr_49", "qr_45", "qr_8", "qr_33", "qr_7", "qr_35", "qr_22", "qr_11", "qr_16", "qr_1" })); - List actualPage3Strings = new ArrayList<>(); - page3.getItems().stream().forEach( ce -> actualPage3Strings.add(ce.getScopeId()) ); - - assertEquals(expectedPage3Strings, actualPage3Strings); - - - List expectedPage1Strings = Arrays.asList(new String[]{"qr_3", "qr_13", "qr_38", "qr_40", "qr_44", "qr_17", "qr_41", "qr_39", "qr_19", "qr_34" }); - - //test first page of the results with empty sort order -> ignored by cassandra datastore - the order is weird, but consistent - PaginationResponse page1EmptySort = testInterface.getForCustomer(customerId_1, null, null, -1, Collections.emptyList(), context); - assertEquals(10, page1EmptySort.getItems().size()); - - List expectedPage1EmptySortStrings = new ArrayList<>(expectedPage1Strings); - List actualPage1EmptySortStrings = new ArrayList<>(); - page1EmptySort.getItems().stream().forEach( ce -> actualPage1EmptySortStrings.add(ce.getScopeId()) ); - - assertEquals(expectedPage1EmptySortStrings, actualPage1EmptySortStrings); - - //test first page of the results with null sort order -> ignored by cassandra datastore - the order is weird, but consistent - PaginationResponse page1NullSort = testInterface.getForCustomer(customerId_1, null, null, -1, null, context); - assertEquals(10, page1NullSort.getItems().size()); - - List expectedPage1NullSortStrings = new ArrayList<>(expectedPage1Strings); - List actualPage1NullSortStrings = new ArrayList<>(); - page1NullSort.getItems().stream().forEach( ce -> actualPage1NullSortStrings.add(ce.getScopeId()) ); - - assertEquals(expectedPage1NullSortStrings, actualPage1NullSortStrings); - - - //test first page of the results with sort descending order by a equipmentId property -> ignored by cassandra datastore - the order is weird, but consistent - PaginationResponse page1SingleSortDesc = testInterface.getForCustomer(customerId_1, null, null, -1, Collections.singletonList(new ColumnAndSort("equipmentId", SortOrder.desc)), context); - assertEquals(10, page1SingleSortDesc.getItems().size()); - - List expectedPage1SingleSortDescStrings = new ArrayList<>(expectedPage1Strings); - List actualPage1SingleSortDescStrings = new ArrayList<>(); - page1SingleSortDesc.getItems().stream().forEach( ce -> actualPage1SingleSortDescStrings.add(ce.getScopeId()) ); - - assertEquals(expectedPage1SingleSortDescStrings, actualPage1SingleSortDescStrings); - - //test with explicit list of equipmentIds and explicit list of AlarmCodes - long createdAfterTs = pastTimestamp + 10; - context = new PaginationContext<>(10); - page1 = testInterface.getForCustomer(customerId_1, equipmentIds, alarmCodes, createdAfterTs, sortBy, context); - page2 = testInterface.getForCustomer(customerId_1, equipmentIds, alarmCodes, createdAfterTs, sortBy, page1.getContext()); - page3 = testInterface.getForCustomer(customerId_1, equipmentIds, alarmCodes, createdAfterTs, sortBy, page2.getContext()); - page4 = testInterface.getForCustomer(customerId_1, equipmentIds, alarmCodes, createdAfterTs, sortBy, page3.getContext()); - page5 = testInterface.getForCustomer(customerId_1, equipmentIds, alarmCodes, createdAfterTs, sortBy, page4.getContext()); - page6 = testInterface.getForCustomer(customerId_1, equipmentIds, alarmCodes, createdAfterTs, sortBy, page5.getContext()); - page7 = testInterface.getForCustomer(customerId_1, equipmentIds, alarmCodes, createdAfterTs, sortBy, page6.getContext()); - - //verify returned pages - assertEquals(10, page1.getItems().size()); - assertEquals(10, page2.getItems().size()); - assertEquals(10, page3.getItems().size()); - assertEquals(10, page4.getItems().size()); - assertEquals(9, page5.getItems().size()); - assertEquals(0, page6.getItems().size()); - - page1.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page2.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page3.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page4.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page5.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - - //test with explicit list of equipmentIds of one element and explicit list of AlarmCodes of one element - context = new PaginationContext<>(10); - page1 = testInterface.getForCustomer(customerId_1, Collections.singleton(equipmentIds.iterator().next()), Collections.singleton(AlarmCode.AccessPointIsUnreachable), -1, sortBy, context); - assertEquals(1, page1.getItems().size()); - - testInterface.resetAlarmCounters(); - - //clean up after the test - equipmentIds.forEach(eqId -> testInterface.delete(customerId_1, eqId)); - equipmentIds_c2.forEach(eqId -> testInterface.delete(customerId_2, eqId)); - - testInterface.resetAlarmCounters(); - + protected List getAlarmPagination_expectedPage3Strings(){ + //in cassandra the sort order is weird but consistent - although it may change on the cassandra server restart + return Arrays.asList(new String[]{"qr_6", "qr_2", "qr_26", "qr_43", "qr_41", "qr_3", "qr_49", "qr_40", "qr_24", "qr_28" }); } - + + @Override + protected List getAlarmPagination_expectedPage1EmptySortStrings() { + return Arrays.asList(new String[]{"qr_17", "qr_14", "qr_9", "qr_38", "qr_18", "qr_30", "qr_0", "qr_7", "qr_25", "qr_19" }); + } + + @Override + protected List getAlarmPagination_expectedPage1SingleSortDescStrings(){ + return getAlarmPagination_expectedPage1EmptySortStrings(); + } + + } diff --git a/alarm-datastore-common-test/src/main/java/com/telecominfraproject/wlan/alarm/datastore/BaseAlarmDatastoreTest.java b/alarm-datastore-common-test/src/main/java/com/telecominfraproject/wlan/alarm/datastore/BaseAlarmDatastoreTest.java index 74553f3a..8805c62d 100644 --- a/alarm-datastore-common-test/src/main/java/com/telecominfraproject/wlan/alarm/datastore/BaseAlarmDatastoreTest.java +++ b/alarm-datastore-common-test/src/main/java/com/telecominfraproject/wlan/alarm/datastore/BaseAlarmDatastoreTest.java @@ -19,6 +19,10 @@ import java.util.concurrent.atomic.AtomicLong; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; +import com.telecominfraproject.wlan.alarm.models.Alarm; +import com.telecominfraproject.wlan.alarm.models.AlarmCode; +import com.telecominfraproject.wlan.alarm.models.AlarmCounts; +import com.telecominfraproject.wlan.alarm.models.AlarmDetails; import com.telecominfraproject.wlan.core.model.json.BaseJsonModel; import com.telecominfraproject.wlan.core.model.pagination.ColumnAndSort; import com.telecominfraproject.wlan.core.model.pagination.PaginationContext; @@ -27,11 +31,6 @@ import com.telecominfraproject.wlan.core.model.pagination.SortOrder; import com.telecominfraproject.wlan.datastore.exceptions.DsConcurrentModificationException; import com.telecominfraproject.wlan.datastore.exceptions.DsEntityNotFoundException; -import com.telecominfraproject.wlan.alarm.models.Alarm; -import com.telecominfraproject.wlan.alarm.models.AlarmCode; -import com.telecominfraproject.wlan.alarm.models.AlarmCounts; -import com.telecominfraproject.wlan.alarm.models.AlarmDetails; - /** * @author dtoptygin * @@ -209,6 +208,9 @@ public abstract class BaseAlarmDatastoreTest { Set equipmentIds = new HashSet<>(); Set alarmCodes = new HashSet<>(Arrays.asList(AlarmCode.AccessPointIsUnreachable, AlarmCode.AssocFailure)); long pastTimestamp = 0; + Set equipmentIds_c2 = new HashSet<>(); + + testInterface.resetAlarmCounters(); for(int i = 0; i< 50; i++){ mdl = createAlarmObject(); @@ -226,10 +228,13 @@ public abstract class BaseAlarmDatastoreTest { testInterface.create(mdl); } + testInterface.resetAlarmCounters(); + for(int i = 0; i< 50; i++){ mdl = createAlarmObject(); mdl.setCustomerId(customerId_2); - mdl.setScopeId("qr_"+apNameIdx); + mdl.setScopeId("qr_"+apNameIdx); + equipmentIds_c2.add(mdl.getEquipmentId()); apNameIdx++; testInterface.create(mdl); } @@ -274,7 +279,7 @@ public abstract class BaseAlarmDatastoreTest { assertTrue(page6.getContext().isLastPage()); assertTrue(page7.getContext().isLastPage()); - List expectedPage3Strings = new ArrayList< >(Arrays.asList(new String[]{"qr_20", "qr_21", "qr_22", "qr_23", "qr_24", "qr_25", "qr_26", "qr_27", "qr_28", "qr_29" })); + List expectedPage3Strings = getAlarmPagination_expectedPage3Strings(); List actualPage3Strings = new ArrayList<>(); page3.getItems().stream().forEach( ce -> actualPage3Strings.add(ce.getScopeId()) ); @@ -285,7 +290,7 @@ public abstract class BaseAlarmDatastoreTest { PaginationResponse page1EmptySort = testInterface.getForCustomer(customerId_1, null, null, -1, Collections.emptyList(), context); assertEquals(10, page1EmptySort.getItems().size()); - List expectedPage1EmptySortStrings = new ArrayList<>(Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" })); + List expectedPage1EmptySortStrings = getAlarmPagination_expectedPage1EmptySortStrings(); List actualPage1EmptySortStrings = new ArrayList<>(); page1EmptySort.getItems().stream().forEach( ce -> actualPage1EmptySortStrings.add(ce.getScopeId()) ); @@ -295,7 +300,7 @@ public abstract class BaseAlarmDatastoreTest { PaginationResponse page1NullSort = testInterface.getForCustomer(customerId_1, null, null, -1, null, context); assertEquals(10, page1NullSort.getItems().size()); - List expectedPage1NullSortStrings = new ArrayList<>(Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" })); + List expectedPage1NullSortStrings = expectedPage1EmptySortStrings; List actualPage1NullSortStrings = new ArrayList<>(); page1NullSort.getItems().stream().forEach( ce -> actualPage1NullSortStrings.add(ce.getScopeId()) ); @@ -306,7 +311,7 @@ public abstract class BaseAlarmDatastoreTest { PaginationResponse page1SingleSortDesc = testInterface.getForCustomer(customerId_1, null, null, -1, Collections.singletonList(new ColumnAndSort("equipmentId", SortOrder.desc)), context); assertEquals(10, page1SingleSortDesc.getItems().size()); - List expectedPage1SingleSortDescStrings = new ArrayList< >(Arrays.asList(new String[]{"qr_49", "qr_48", "qr_47", "qr_46", "qr_45", "qr_44", "qr_43", "qr_42", "qr_41", "qr_40" })); + List expectedPage1SingleSortDescStrings = getAlarmPagination_expectedPage1SingleSortDescStrings(); List actualPage1SingleSortDescStrings = new ArrayList<>(); page1SingleSortDesc.getItems().stream().forEach( ce -> actualPage1SingleSortDescStrings.add(ce.getScopeId()) ); @@ -342,8 +347,29 @@ public abstract class BaseAlarmDatastoreTest { page1 = testInterface.getForCustomer(customerId_1, Collections.singleton(equipmentIds.iterator().next()), Collections.singleton(AlarmCode.AccessPointIsUnreachable), -1, sortBy, context); assertEquals(1, page1.getItems().size()); + testInterface.resetAlarmCounters(); + + //clean up after the test + equipmentIds.forEach(eqId -> testInterface.delete(customerId_1, eqId)); + equipmentIds_c2.forEach(eqId -> testInterface.delete(customerId_2, eqId)); + + testInterface.resetAlarmCounters(); + } + protected List getAlarmPagination_expectedPage3Strings(){ + return Arrays.asList(new String[]{"qr_20", "qr_21", "qr_22", "qr_23", "qr_24", "qr_25", "qr_26", "qr_27", "qr_28", "qr_29" }); + } + + protected List getAlarmPagination_expectedPage1EmptySortStrings() { + return Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" }); + } + + protected List getAlarmPagination_expectedPage1SingleSortDescStrings(){ + return Arrays.asList(new String[]{"qr_49", "qr_48", "qr_47", "qr_46", "qr_45", "qr_44", "qr_43", "qr_42", "qr_41", "qr_40" }); + } + + @Test public void testAlarmCountsModel() { AlarmCounts alarmCounts = new AlarmCounts(); diff --git a/client-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/client/datastore/cassandra/ClientDAO.java b/client-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/client/datastore/cassandra/ClientDAO.java index 809f8e01..054f9f0c 100644 --- a/client-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/client/datastore/cassandra/ClientDAO.java +++ b/client-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/client/datastore/cassandra/ClientDAO.java @@ -440,7 +440,7 @@ public class ClientDAO { ArrayList bindVars = new ArrayList<>(); BoundStatement boundStmt; - if (macSubstring != null) { + if (macSubstring != null && !macSubstring.isEmpty()) { bindVars.add(customerId); bindVars.add("%" + macSubstring.toLowerCase() + "%"); @@ -493,6 +493,15 @@ public class ClientDAO { // startAfterItem is not used in Cassandra datastores, set it to null ret.getContext().setStartAfterItem(null); + + //in cassandra we will rely only on nextPagingState to set the lastPage indicator + ret.getContext().setLastPage(false); + + if(nextPagingState == null) { + //in cassandra, if there are no more pages available, the pagingState is returned as null by the driver + //this overrides all other heuristics related to guessing the indication of the last page + ret.getContext().setLastPage(true); + } return ret; @@ -565,6 +574,15 @@ public class ClientDAO { // startAfterItem is not used in Cassandra datastores, set it to null ret.getContext().setStartAfterItem(null); + //in cassandra we will rely only on nextPagingState to set the lastPage indicator + ret.getContext().setLastPage(false); + + if(nextPagingState == null) { + //in cassandra, if there are no more pages available, the pagingState is returned as null by the driver + //this overrides all other heuristics related to guessing the indication of the last page + ret.getContext().setLastPage(true); + } + return ret; } diff --git a/client-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/client/datastore/cassandra/ClientSessionDAO.java b/client-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/client/datastore/cassandra/ClientSessionDAO.java index 38a5c17f..8e42a815 100644 --- a/client-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/client/datastore/cassandra/ClientSessionDAO.java +++ b/client-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/client/datastore/cassandra/ClientSessionDAO.java @@ -498,6 +498,15 @@ public class ClientSessionDAO { // startAfterItem is not used in Cassandra datastores, set it to null ret.getContext().setStartAfterItem(null); + //in cassandra we will rely only on nextPagingState to set the lastPage indicator + ret.getContext().setLastPage(false); + + if(nextPagingState == null) { + //in cassandra, if there are no more pages available, the pagingState is returned as null by the driver + //this overrides all other heuristics related to guessing the indication of the last page + ret.getContext().setLastPage(true); + } + return ret; } } diff --git a/client-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/client/datastore/cassandra/ClientDatastoreCassandraTests.java b/client-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/client/datastore/cassandra/ClientDatastoreCassandraTests.java index 85df100d..593a8135 100644 --- a/client-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/client/datastore/cassandra/ClientDatastoreCassandraTests.java +++ b/client-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/client/datastore/cassandra/ClientDatastoreCassandraTests.java @@ -1,18 +1,10 @@ package com.telecominfraproject.wlan.client.datastore.cassandra; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; import org.junit.Ignore; -import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -20,15 +12,6 @@ import org.springframework.context.annotation.Import; import org.springframework.test.context.junit4.SpringRunner; import com.telecominfraproject.wlan.client.datastore.BaseClientDatastoreTest; -import com.telecominfraproject.wlan.client.info.models.ClientInfoDetails; -import com.telecominfraproject.wlan.client.models.Client; -import com.telecominfraproject.wlan.client.session.models.ClientSession; -import com.telecominfraproject.wlan.client.session.models.ClientSessionDetails; -import com.telecominfraproject.wlan.core.model.equipment.MacAddress; -import com.telecominfraproject.wlan.core.model.pagination.ColumnAndSort; -import com.telecominfraproject.wlan.core.model.pagination.PaginationContext; -import com.telecominfraproject.wlan.core.model.pagination.PaginationResponse; -import com.telecominfraproject.wlan.core.model.pagination.SortOrder; import com.telecominfraproject.wlan.core.server.cassandra.BaseCassandraDataSource; import com.telecominfraproject.wlan.core.server.cassandra.test.BaseCassandraTest; @@ -43,410 +26,46 @@ import com.telecominfraproject.wlan.core.server.cassandra.test.BaseCassandraTest @Ignore("Ignore Cassandra Tests until we can set up a cassandra cluster for the integration testing") public class ClientDatastoreCassandraTests extends BaseClientDatastoreTest { - @Test - public void testClientPagination() - { - //create 100 Clients - Client mdl; - int customerId_1 = (int) testSequence.incrementAndGet(); - int customerId_2 = (int) testSequence.incrementAndGet(); - - List created_models = new ArrayList<>(); - - int apNameIdx = 0; - - for(int i = 0; i< 50; i++){ - mdl = new Client(); - mdl.setCustomerId(customerId_1); - ClientInfoDetails details = new ClientInfoDetails(); - details.setAlias("qr_"+apNameIdx); - mdl.setDetails(details ); - mdl.setMacAddress(new MacAddress((long)i)); - apNameIdx++; - mdl = testInterface.create(mdl); - created_models.add(mdl); - } + @Override + protected List getClientPagination_ExpectedPage3Strings() { + //in cassandra the sort order is weird but consistent - although it may change on the cassandra server restart + return new ArrayList<>(Arrays.asList(new String[]{"qr_0", "qr_13", "qr_47", "qr_4", "qr_36", "qr_21", "qr_12", "qr_27", "qr_20", "qr_19" })); + } - for(int i = 0; i< 50; i++){ - mdl = new Client(); - mdl.setCustomerId(customerId_2); - ClientInfoDetails details = new ClientInfoDetails(); - details.setAlias("qr_"+apNameIdx); - mdl.setDetails(details ); - mdl.setMacAddress(new MacAddress((long)i)); - - apNameIdx++; - mdl = testInterface.create(mdl); - created_models.add(mdl); - } + @Override + protected List getClientPagination_ExpectedPage1EmptySortStrings(){ + return new ArrayList<>(Arrays.asList(new String[]{"qr_46", "qr_9", "qr_3", "qr_6", "qr_1", "qr_26", "qr_10", "qr_40", "qr_14", "qr_42" })); + } - //paginate over Clients - - List sortBy = new ArrayList<>(); - //Cassandra has limited support for sorting. Not going to sort the results - //sortBy.addAll(Arrays.asList(new ColumnAndSort("macAddress"))); - - PaginationContext context = new PaginationContext<>(10); - PaginationResponse page1 = testInterface.getForCustomer(customerId_1, sortBy, context); - PaginationResponse page2 = testInterface.getForCustomer(customerId_1, sortBy, page1.getContext()); - PaginationResponse page3 = testInterface.getForCustomer(customerId_1, sortBy, page2.getContext()); - PaginationResponse page4 = testInterface.getForCustomer(customerId_1, sortBy, page3.getContext()); - PaginationResponse page5 = testInterface.getForCustomer(customerId_1, sortBy, page4.getContext()); - PaginationResponse page6 = testInterface.getForCustomer(customerId_1, sortBy, page5.getContext()); - PaginationResponse page7 = testInterface.getForCustomer(customerId_1, sortBy, page6.getContext()); - - //verify returned pages - assertEquals(10, page1.getItems().size()); - assertEquals(10, page2.getItems().size()); - assertEquals(10, page3.getItems().size()); - assertEquals(10, page4.getItems().size()); - assertEquals(10, page5.getItems().size()); - - page1.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page2.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page3.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page4.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page5.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - - assertEquals(0, page6.getItems().size()); - assertEquals(0, page7.getItems().size()); - - assertFalse(page1.getContext().isLastPage()); - assertFalse(page2.getContext().isLastPage()); - assertFalse(page3.getContext().isLastPage()); - assertFalse(page4.getContext().isLastPage()); - assertFalse(page5.getContext().isLastPage()); - - assertTrue(page6.getContext().isLastPage()); - assertTrue(page7.getContext().isLastPage()); - - //sort order is weird but consistent - List expectedPage3Strings = new ArrayList< >(Arrays.asList(new String[]{"qr_48", "qr_30", "qr_31", "qr_12", "qr_8", "qr_9", "qr_17", "qr_49", "qr_14", "qr_43" })); - List actualPage3Strings = new ArrayList<>(); - page3.getItems().stream().forEach( ce -> actualPage3Strings.add(((ClientInfoDetails)ce.getDetails()).getAlias()) ); - - assertEquals(expectedPage3Strings, actualPage3Strings); - - //test first page of the results with empty sort order -> sort order is weird but consistent - PaginationResponse page1EmptySort = testInterface.getForCustomer(customerId_1, Collections.emptyList(), context); - assertEquals(10, page1EmptySort.getItems().size()); + - List expectedPage1EmptySortStrings = new ArrayList<>(Arrays.asList(new String[]{"qr_29", "qr_44", "qr_13", "qr_23", "qr_47", "qr_3", "qr_36", "qr_33", "qr_11", "qr_45" })); - List actualPage1EmptySortStrings = new ArrayList<>(); - page1EmptySort.getItems().stream().forEach( ce -> actualPage1EmptySortStrings.add(((ClientInfoDetails)ce.getDetails()).getAlias()) ); - assertEquals(expectedPage1EmptySortStrings, actualPage1EmptySortStrings); + @Override + protected List getSearchByMac_ExpectedPage1SingleSortDescStrings() { + return new ArrayList<>(Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" })); + } - //test first page of the results with null sort order -> sort order is weird but consistent - PaginationResponse page1NullSort = testInterface.getForCustomer(customerId_1, null, context); - assertEquals(10, page1NullSort.getItems().size()); - - List expectedPage1NullSortStrings = new ArrayList<>(expectedPage1EmptySortStrings); - List actualPage1NullSortStrings = new ArrayList<>(); - page1NullSort.getItems().stream().forEach( ce -> actualPage1NullSortStrings.add(((ClientInfoDetails)ce.getDetails()).getAlias()) ); - - assertEquals(expectedPage1NullSortStrings, actualPage1NullSortStrings); - - - //test first page of the results with sort descending order by a macAddress property -> sort order is weird but consistent - PaginationResponse page1SingleSortDesc = testInterface.getForCustomer(customerId_1, Collections.singletonList(new ColumnAndSort("macAddress", SortOrder.desc)), context); - assertEquals(10, page1SingleSortDesc.getItems().size()); - - List expectedPage1SingleSortDescStrings = new ArrayList<>(expectedPage1EmptySortStrings); - List actualPage1SingleSortDescStrings = new ArrayList<>(); - page1SingleSortDesc.getItems().stream().forEach( ce -> actualPage1SingleSortDescStrings.add(((ClientInfoDetails)ce.getDetails()).getAlias()) ); - - assertEquals(expectedPage1SingleSortDescStrings, actualPage1SingleSortDescStrings); - - created_models.forEach(m -> testInterface.delete(m.getCustomerId(), m.getMacAddress())); - + @Override + protected List getClientPagination_ExpectedPage1SingleSortDescStrings() { + return getClientPagination_ExpectedPage1EmptySortStrings(); } - @Test - public void testClientSessionPagination() - { - //create 100 Client sessions - ClientSession mdl; - int customerId_1 = (int) testSequence.incrementAndGet(); - int customerId_2 = (int) testSequence.incrementAndGet(); - long equipmentId_1 = testSequence.incrementAndGet(); - long equipmentId_2 = testSequence.incrementAndGet(); - long locationId_1 = testSequence.incrementAndGet(); - long locationId_2 = testSequence.incrementAndGet(); - - int apNameIdx = 0; - - List sessionsToCreate = new ArrayList<>(); - - for(int i = 0; i< 50; i++){ - mdl = new ClientSession(); - mdl.setCustomerId(customerId_1); - if(i<10) { - mdl.setEquipmentId(equipmentId_1); - mdl.setLocationId(locationId_1); - } else if(i<20) { - mdl.setEquipmentId(equipmentId_2); - mdl.setLocationId(locationId_2); - } else { - mdl.setEquipmentId(testSequence.incrementAndGet()); - } - - ClientSessionDetails details = new ClientSessionDetails(); - details.setApFingerprint("qr_"+apNameIdx); - mdl.setDetails(details ); - mdl.setMacAddress(new MacAddress((long)i)); - - apNameIdx++; - - sessionsToCreate.add(mdl); - } - - List createdList = testInterface.updateSessions(sessionsToCreate); - List createdDetailsList = new ArrayList<>(); - List detailsToCreateList = new ArrayList<>(); - - sessionsToCreate.forEach(s -> detailsToCreateList.add(s.getDetails())); - createdList.forEach(s -> createdDetailsList.add(s.getDetails())); - assertEquals(detailsToCreateList, createdDetailsList); - - - List createdListExtra = new ArrayList<>(); - - for(int i = 0; i< 50; i++){ - mdl = new ClientSession(); - mdl.setCustomerId(customerId_2); - mdl.setEquipmentId(testSequence.incrementAndGet()); - mdl.setLocationId(testSequence.incrementAndGet()); - ClientSessionDetails details = new ClientSessionDetails(); - details.setApFingerprint("qr_"+apNameIdx); - mdl.setDetails(details ); - mdl.setMacAddress(new MacAddress((long)i)); - - apNameIdx++; - mdl = testInterface.updateSession(mdl); - createdListExtra.add(mdl); - } - - //paginate over Clients - - List sortBy = new ArrayList<>(); - //Cassandra has limited support for sorting, we're not using that feature - //sortBy.addAll(Arrays.asList(new ColumnAndSort("macAddress"))); - - PaginationContext context = new PaginationContext<>(10); - PaginationResponse page1 = testInterface.getSessionsForCustomer(customerId_1, null, null, sortBy, context); - PaginationResponse page2 = testInterface.getSessionsForCustomer(customerId_1, null, null, sortBy, page1.getContext()); - PaginationResponse page3 = testInterface.getSessionsForCustomer(customerId_1, null, null, sortBy, page2.getContext()); - PaginationResponse page4 = testInterface.getSessionsForCustomer(customerId_1, null, null, sortBy, page3.getContext()); - PaginationResponse page5 = testInterface.getSessionsForCustomer(customerId_1, null, null, sortBy, page4.getContext()); - PaginationResponse page6 = testInterface.getSessionsForCustomer(customerId_1, null, null, sortBy, page5.getContext()); - PaginationResponse page7 = testInterface.getSessionsForCustomer(customerId_1, null, null, sortBy, page6.getContext()); - - //verify returned pages - assertEquals(10, page1.getItems().size()); - assertEquals(10, page2.getItems().size()); - assertEquals(10, page3.getItems().size()); - assertEquals(10, page4.getItems().size()); - assertEquals(10, page5.getItems().size()); - - page1.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page2.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page3.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page4.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page5.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - - assertEquals(0, page6.getItems().size()); - assertEquals(0, page7.getItems().size()); - - assertFalse(page1.getContext().isLastPage()); - assertFalse(page2.getContext().isLastPage()); - assertFalse(page3.getContext().isLastPage()); - assertFalse(page4.getContext().isLastPage()); - assertFalse(page5.getContext().isLastPage()); - - assertTrue(page6.getContext().isLastPage()); - assertTrue(page7.getContext().isLastPage()); - - Set expectedAllPagesStrings = new HashSet<>(); - for(int i=0; i<50; i++) { - expectedAllPagesStrings.add("qr_"+i); - } - Set actualPage3Strings = new HashSet<>(); - - page1.getItems().stream().forEach( ce -> actualPage3Strings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); - page2.getItems().stream().forEach( ce -> actualPage3Strings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); - page3.getItems().stream().forEach( ce -> actualPage3Strings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); - page4.getItems().stream().forEach( ce -> actualPage3Strings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); - page5.getItems().stream().forEach( ce -> actualPage3Strings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); - - assertEquals(expectedAllPagesStrings, actualPage3Strings); - - - PaginationContext context100 = new PaginationContext<>(100); - //test first page of the results with empty sort order -> sort order is weird but consistent - PaginationResponse page1EmptySort = testInterface.getSessionsForCustomer(customerId_1, null, null, Collections.emptyList(), context100); - assertEquals(50, page1EmptySort.getItems().size()); - - Set expectedPage1EmptySortStrings = new HashSet<>(expectedAllPagesStrings); - - Set actualPage1EmptySortStrings = new HashSet<>(); - page1EmptySort.getItems().stream().forEach( ce -> actualPage1EmptySortStrings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); - - assertEquals(expectedPage1EmptySortStrings, actualPage1EmptySortStrings); - - //test first page of the results with null sort order -> sort order is weird but consistent - PaginationResponse page1NullSort = testInterface.getSessionsForCustomer(customerId_1, null, null, null, context100); - assertEquals(50, page1NullSort.getItems().size()); - - Set expectedPage1NullSortStrings = new HashSet<>(expectedPage1EmptySortStrings); - Set actualPage1NullSortStrings = new HashSet<>(); - page1NullSort.getItems().stream().forEach( ce -> actualPage1NullSortStrings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); - - assertEquals(expectedPage1NullSortStrings, actualPage1NullSortStrings); - - - //test first page of the results with sort descending order by a macAddress property -> sort order is weird but consistent - PaginationResponse page1SingleSortDesc = testInterface.getSessionsForCustomer(customerId_1, null, null, Collections.singletonList(new ColumnAndSort("macAddress", SortOrder.desc)), context100); - assertEquals(50, page1SingleSortDesc.getItems().size()); - - Set expectedPage1SingleSortDescStrings = new HashSet<>(expectedPage1EmptySortStrings); - Set actualPage1SingleSortDescStrings = new HashSet<>(); - page1SingleSortDesc.getItems().stream().forEach( ce -> actualPage1SingleSortDescStrings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); - - assertEquals(expectedPage1SingleSortDescStrings, actualPage1SingleSortDescStrings); - - //test the results for equipment_1 only - PaginationResponse page1Eq_1 = testInterface.getSessionsForCustomer(customerId_1, new HashSet(Arrays.asList(equipmentId_1)), null, Collections.emptyList(), context); - PaginationResponse page2Eq_1 = testInterface.getSessionsForCustomer(customerId_1, new HashSet(Arrays.asList(equipmentId_1)), null, Collections.emptyList(), page1Eq_1.getContext()); - - assertEquals(10, page1Eq_1.getItems().size()); - assertEquals(0, page2Eq_1.getItems().size()); - assertFalse(page1Eq_1.getContext().isLastPage()); - assertTrue(page2Eq_1.getContext().isLastPage()); - - List expectedPage1Eq_1Strings = new ArrayList<>(Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" })); - List actualPage1Eq_1Strings = new ArrayList<>(); - page1Eq_1.getItems().stream().forEach( ce -> actualPage1Eq_1Strings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); - - assertEquals(expectedPage1Eq_1Strings, actualPage1Eq_1Strings); - - //test the results for equipment_2 only - PaginationResponse page1Eq_2 = testInterface.getSessionsForCustomer(customerId_1, new HashSet(Arrays.asList(equipmentId_2)), null, Collections.emptyList(), context); - PaginationResponse page2Eq_2 = testInterface.getSessionsForCustomer(customerId_1, new HashSet(Arrays.asList(equipmentId_2)), null, Collections.emptyList(), page1Eq_2.getContext()); - - assertEquals(10, page1Eq_2.getItems().size()); - assertEquals(0, page2Eq_2.getItems().size()); - assertFalse(page1Eq_2.getContext().isLastPage()); - assertTrue(page2Eq_2.getContext().isLastPage()); - - List expectedPage1Eq_2Strings = new ArrayList<>(Arrays.asList(new String[]{"qr_10", "qr_11", "qr_12", "qr_13", "qr_14", "qr_15", "qr_16", "qr_17", "qr_18", "qr_19"})); - List actualPage1Eq_2Strings = new ArrayList<>(); - page1Eq_2.getItems().stream().forEach( ce -> actualPage1Eq_2Strings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); - - assertEquals(expectedPage1Eq_2Strings, actualPage1Eq_2Strings); - - - //test the results for equipment_1 or equipment_2 only - PaginationResponse page1Eq_1or2 = testInterface.getSessionsForCustomer(customerId_1, new HashSet(Arrays.asList(equipmentId_1, equipmentId_2)), null, Collections.emptyList(), context); - PaginationResponse page2Eq_1or2 = testInterface.getSessionsForCustomer(customerId_1, new HashSet(Arrays.asList(equipmentId_1, equipmentId_2)), null, Collections.emptyList(), page1Eq_1or2.getContext()); - PaginationResponse page3Eq_1or2 = testInterface.getSessionsForCustomer(customerId_1, new HashSet(Arrays.asList(equipmentId_1, equipmentId_2)), null, Collections.emptyList(), page2Eq_1or2.getContext()); - - assertEquals(10, page1Eq_1or2.getItems().size()); - assertEquals(10, page2Eq_1or2.getItems().size()); - assertEquals(0, page3Eq_1or2.getItems().size()); - assertFalse(page1Eq_1or2.getContext().isLastPage()); - assertFalse(page2Eq_1or2.getContext().isLastPage()); - assertTrue(page3Eq_1or2.getContext().isLastPage()); - - List expectedPage1Eq_1or2Strings = new ArrayList<>(Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" })); - List actualPage1Eq_1or2Strings = new ArrayList<>(); - page1Eq_1or2.getItems().stream().forEach( ce -> actualPage1Eq_1or2Strings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); - - assertEquals(expectedPage1Eq_1or2Strings, actualPage1Eq_1or2Strings); - - List expectedPage2Eq_1or2Strings = new ArrayList<>(Arrays.asList(new String[]{"qr_10", "qr_11", "qr_12", "qr_13", "qr_14", "qr_15", "qr_16", "qr_17", "qr_18", "qr_19" })); - List actualPage2Eq_1or2Strings = new ArrayList<>(); - page2Eq_1or2.getItems().stream().forEach( ce -> actualPage2Eq_1or2Strings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); - - assertEquals(expectedPage2Eq_1or2Strings, actualPage2Eq_1or2Strings); - - // - // test filters on locationIds - // - - //test the results for location_1 only - page1Eq_1 = testInterface.getSessionsForCustomer(customerId_1, null, new HashSet(Arrays.asList(locationId_1)), Collections.emptyList(), context); - page2Eq_1 = testInterface.getSessionsForCustomer(customerId_1, null, new HashSet(Arrays.asList(locationId_1)), Collections.emptyList(), page1Eq_1.getContext()); - - assertEquals(10, page1Eq_1.getItems().size()); - assertEquals(0, page2Eq_1.getItems().size()); - assertFalse(page1Eq_1.getContext().isLastPage()); - assertTrue(page2Eq_1.getContext().isLastPage()); - - expectedPage1Eq_1Strings = new ArrayList<>(Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" })); - List actualPage1Loc_1Strings = new ArrayList<>(); - page1Eq_1.getItems().stream().forEach( ce -> actualPage1Loc_1Strings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); - - assertEquals(expectedPage1Eq_1Strings, actualPage1Loc_1Strings); - - //test the results for location_2 only - page1Eq_2 = testInterface.getSessionsForCustomer(customerId_1, null, new HashSet(Arrays.asList(locationId_2)), Collections.emptyList(), context); - page2Eq_2 = testInterface.getSessionsForCustomer(customerId_1, null, new HashSet(Arrays.asList(locationId_2)), Collections.emptyList(), page1Eq_2.getContext()); - - assertEquals(10, page1Eq_2.getItems().size()); - assertEquals(0, page2Eq_2.getItems().size()); - assertFalse(page1Eq_2.getContext().isLastPage()); - assertTrue(page2Eq_2.getContext().isLastPage()); - - expectedPage1Eq_2Strings = new ArrayList<>(Arrays.asList(new String[]{"qr_10", "qr_11", "qr_12", "qr_13", "qr_14", "qr_15", "qr_16", "qr_17", "qr_18", "qr_19"})); - List actualPage1Loc_2Strings = new ArrayList<>(); - page1Eq_2.getItems().stream().forEach( ce -> actualPage1Loc_2Strings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); - - assertEquals(expectedPage1Eq_2Strings, actualPage1Loc_2Strings); - - - //test the results for location_1 or location_2 only - page1Eq_1or2 = testInterface.getSessionsForCustomer(customerId_1, null, new HashSet(Arrays.asList(locationId_1, locationId_2)), Collections.emptyList(), context); - page2Eq_1or2 = testInterface.getSessionsForCustomer(customerId_1, null, new HashSet(Arrays.asList(locationId_1, locationId_2)), Collections.emptyList(), page1Eq_1or2.getContext()); - page3Eq_1or2 = testInterface.getSessionsForCustomer(customerId_1, null, new HashSet(Arrays.asList(locationId_1, locationId_2)), Collections.emptyList(), page2Eq_1or2.getContext()); - - assertEquals(10, page1Eq_1or2.getItems().size()); - assertEquals(10, page2Eq_1or2.getItems().size()); - assertEquals(0, page3Eq_1or2.getItems().size()); - assertFalse(page1Eq_1or2.getContext().isLastPage()); - assertFalse(page2Eq_1or2.getContext().isLastPage()); - assertTrue(page3Eq_1or2.getContext().isLastPage()); - - expectedPage1Eq_1or2Strings = new ArrayList<>(Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" })); - List actualPage1Loc_1or2Strings = new ArrayList<>(); - page1Eq_1or2.getItems().stream().forEach( ce -> actualPage1Loc_1or2Strings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); - - assertEquals(expectedPage1Eq_1or2Strings, actualPage1Loc_1or2Strings); - - expectedPage2Eq_1or2Strings = new ArrayList<>(Arrays.asList(new String[]{"qr_10", "qr_11", "qr_12", "qr_13", "qr_14", "qr_15", "qr_16", "qr_17", "qr_18", "qr_19" })); - List actualPage2Loc_1or2Strings = new ArrayList<>(); - page2Eq_1or2.getItems().stream().forEach( ce -> actualPage2Loc_1or2Strings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); - - assertEquals(expectedPage2Eq_1or2Strings, actualPage2Loc_1or2Strings); - - //test the results for ( location_1 or location_2 ) and equipment_1only - page1Eq_1 = testInterface.getSessionsForCustomer(customerId_1, new HashSet(Arrays.asList(equipmentId_1)), new HashSet(Arrays.asList(locationId_1, locationId_2)), Collections.emptyList(), context); - page2Eq_1 = testInterface.getSessionsForCustomer(customerId_1, new HashSet(Arrays.asList(equipmentId_1)), new HashSet(Arrays.asList(locationId_1, locationId_2)), Collections.emptyList(), page1Eq_1.getContext()); - - assertEquals(10, page1Eq_1.getItems().size()); - assertEquals(0, page2Eq_1.getItems().size()); - assertFalse(page1Eq_1.getContext().isLastPage()); - assertTrue(page2Eq_1.getContext().isLastPage()); - - expectedPage1Eq_1Strings = new ArrayList<>(expectedPage1Eq_1or2Strings); - List actualPage1Loc_121Strings = new ArrayList<>(); - page1Eq_1.getItems().stream().forEach( ce -> actualPage1Loc_121Strings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); - - assertEquals(expectedPage1Eq_1Strings, actualPage1Loc_121Strings); - - createdList.forEach(c -> testInterface.deleteSession(c.getCustomerId(), c.getEquipmentId(), c.getMacAddress())); - createdListExtra.forEach(c -> testInterface.deleteSession(c.getCustomerId(), c.getEquipmentId(), c.getMacAddress())); + @Override + protected List getClientSessionPagination_expectedPage1EmptySortStrings(){ + return new ArrayList<>(Arrays.asList(new String[]{"qr_30", "qr_43", "qr_18", "qr_9", "qr_10", "qr_23", "qr_20", "qr_47", "qr_1", "qr_40" })); } + + @Override + protected List getClientSessionPagination_expectedPage3Strings(){ + return new ArrayList<>(Arrays.asList(new String[]{"qr_42", "qr_16", "qr_27", "qr_36", "qr_48", "qr_13", "qr_39", "qr_28", "qr_15", "qr_29" })); + } + + @Override + protected List getClientSessionPagination_expectedPage1SingleSortDescStrings() { + return getClientSessionPagination_expectedPage1EmptySortStrings(); + } + + } diff --git a/client-datastore-common-test/src/main/java/com/telecominfraproject/wlan/client/datastore/BaseClientDatastoreTest.java b/client-datastore-common-test/src/main/java/com/telecominfraproject/wlan/client/datastore/BaseClientDatastoreTest.java index 9a106adb..ce0944df 100644 --- a/client-datastore-common-test/src/main/java/com/telecominfraproject/wlan/client/datastore/BaseClientDatastoreTest.java +++ b/client-datastore-common-test/src/main/java/com/telecominfraproject/wlan/client/datastore/BaseClientDatastoreTest.java @@ -264,7 +264,7 @@ public abstract class BaseClientDatastoreTest { PaginationResponse page1SingleSortDesc = testInterface.searchByMacAddress(customerId_1, "A1", Collections.singletonList(new ColumnAndSort("macAddress", SortOrder.desc)), context); assertEquals(10, page1SingleSortDesc.getItems().size()); - List expectedPage1SingleSortDescStrings = new ArrayList<>(Arrays.asList(new String[]{"qr_49", "qr_48", "qr_47", "qr_46", "qr_45", "qr_44", "qr_43", "qr_42", "qr_41", "qr_40" })); + List expectedPage1SingleSortDescStrings = getSearchByMac_ExpectedPage1SingleSortDescStrings(); List actualPage1SingleSortDescStrings = new ArrayList<>(); page1SingleSortDesc.getItems().stream().forEach( ce -> actualPage1SingleSortDescStrings.add(((ClientInfoDetails)ce.getDetails()).getAlias()) ); @@ -274,6 +274,13 @@ public abstract class BaseClientDatastoreTest { } + /** + * This method is overridden in the cassandra datastore because cassandra does not handle sort order + */ + protected List getSearchByMac_ExpectedPage1SingleSortDescStrings(){ + return new ArrayList<>(Arrays.asList(new String[]{"qr_49", "qr_48", "qr_47", "qr_46", "qr_45", "qr_44", "qr_43", "qr_42", "qr_41", "qr_40" })); + } + @Test public void testEmptyNullSearchMacSubstring() { Client mdl; @@ -436,7 +443,7 @@ public abstract class BaseClientDatastoreTest { assertTrue(page6.getContext().isLastPage()); assertTrue(page7.getContext().isLastPage()); - List expectedPage3Strings = new ArrayList< >(Arrays.asList(new String[]{"qr_20", "qr_21", "qr_22", "qr_23", "qr_24", "qr_25", "qr_26", "qr_27", "qr_28", "qr_29" })); + List expectedPage3Strings = getClientPagination_ExpectedPage3Strings(); List actualPage3Strings = new ArrayList<>(); page3.getItems().stream().forEach( ce -> actualPage3Strings.add(((ClientInfoDetails)ce.getDetails()).getAlias()) ); @@ -447,7 +454,7 @@ public abstract class BaseClientDatastoreTest { PaginationResponse page1EmptySort = testInterface.getForCustomer(customerId_1, Collections.emptyList(), context); assertEquals(10, page1EmptySort.getItems().size()); - List expectedPage1EmptySortStrings = new ArrayList<>(Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" })); + List expectedPage1EmptySortStrings = getClientPagination_ExpectedPage1EmptySortStrings(); List actualPage1EmptySortStrings = new ArrayList<>(); page1EmptySort.getItems().stream().forEach( ce -> actualPage1EmptySortStrings.add(((ClientInfoDetails)ce.getDetails()).getAlias()) ); @@ -457,7 +464,7 @@ public abstract class BaseClientDatastoreTest { PaginationResponse page1NullSort = testInterface.getForCustomer(customerId_1, null, context); assertEquals(10, page1NullSort.getItems().size()); - List expectedPage1NullSortStrings = new ArrayList<>(Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" })); + List expectedPage1NullSortStrings = new ArrayList<>(expectedPage1EmptySortStrings); List actualPage1NullSortStrings = new ArrayList<>(); page1NullSort.getItems().stream().forEach( ce -> actualPage1NullSortStrings.add(((ClientInfoDetails)ce.getDetails()).getAlias()) ); @@ -468,7 +475,7 @@ public abstract class BaseClientDatastoreTest { PaginationResponse page1SingleSortDesc = testInterface.getForCustomer(customerId_1, Collections.singletonList(new ColumnAndSort("macAddress", SortOrder.desc)), context); assertEquals(10, page1SingleSortDesc.getItems().size()); - List expectedPage1SingleSortDescStrings = new ArrayList< >(Arrays.asList(new String[]{"qr_49", "qr_48", "qr_47", "qr_46", "qr_45", "qr_44", "qr_43", "qr_42", "qr_41", "qr_40" })); + List expectedPage1SingleSortDescStrings = getClientPagination_ExpectedPage1SingleSortDescStrings(); List actualPage1SingleSortDescStrings = new ArrayList<>(); page1SingleSortDesc.getItems().stream().forEach( ce -> actualPage1SingleSortDescStrings.add(((ClientInfoDetails)ce.getDetails()).getAlias()) ); @@ -478,6 +485,18 @@ public abstract class BaseClientDatastoreTest { } + protected List getClientPagination_ExpectedPage3Strings() { + return new ArrayList<>(Arrays.asList(new String[]{"qr_20", "qr_21", "qr_22", "qr_23", "qr_24", "qr_25", "qr_26", "qr_27", "qr_28", "qr_29" })); + } + + protected List getClientPagination_ExpectedPage1EmptySortStrings(){ + return new ArrayList<>(Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" })); + } + + protected List getClientPagination_ExpectedPage1SingleSortDescStrings(){ + return new ArrayList<>(Arrays.asList(new String[]{"qr_49", "qr_48", "qr_47", "qr_46", "qr_45", "qr_44", "qr_43", "qr_42", "qr_41", "qr_40" })); + } + // // Client session tests @@ -849,8 +868,22 @@ public abstract class BaseClientDatastoreTest { assertTrue(page6.getContext().isLastPage()); assertTrue(page7.getContext().isLastPage()); + + Set expectedAllPagesStrings = new HashSet<>(); + for(int i=0; i<50; i++) { + expectedAllPagesStrings.add("qr_"+i); + } + Set actualAllPagesStrings = new HashSet<>(); - List expectedPage3Strings = new ArrayList< >(Arrays.asList(new String[]{"qr_20", "qr_21", "qr_22", "qr_23", "qr_24", "qr_25", "qr_26", "qr_27", "qr_28", "qr_29" })); + page1.getItems().stream().forEach( ce -> actualAllPagesStrings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); + page2.getItems().stream().forEach( ce -> actualAllPagesStrings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); + page3.getItems().stream().forEach( ce -> actualAllPagesStrings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); + page4.getItems().stream().forEach( ce -> actualAllPagesStrings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); + page5.getItems().stream().forEach( ce -> actualAllPagesStrings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); + + assertEquals(expectedAllPagesStrings, actualAllPagesStrings); + + List expectedPage3Strings = getClientSessionPagination_expectedPage3Strings(); List actualPage3Strings = new ArrayList<>(); page3.getItems().stream().forEach( ce -> actualPage3Strings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); @@ -861,7 +894,7 @@ public abstract class BaseClientDatastoreTest { PaginationResponse page1EmptySort = testInterface.getSessionsForCustomer(customerId_1, null, null, Collections.emptyList(), context); assertEquals(10, page1EmptySort.getItems().size()); - List expectedPage1EmptySortStrings = new ArrayList<>(Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" })); + List expectedPage1EmptySortStrings = getClientSessionPagination_expectedPage1EmptySortStrings(); List actualPage1EmptySortStrings = new ArrayList<>(); page1EmptySort.getItems().stream().forEach( ce -> actualPage1EmptySortStrings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); @@ -871,7 +904,7 @@ public abstract class BaseClientDatastoreTest { PaginationResponse page1NullSort = testInterface.getSessionsForCustomer(customerId_1, null, null, null, context); assertEquals(10, page1NullSort.getItems().size()); - List expectedPage1NullSortStrings = new ArrayList<>(Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" })); + List expectedPage1NullSortStrings = getClientSessionPagination_expectedPage1EmptySortStrings(); List actualPage1NullSortStrings = new ArrayList<>(); page1NullSort.getItems().stream().forEach( ce -> actualPage1NullSortStrings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); @@ -882,7 +915,7 @@ public abstract class BaseClientDatastoreTest { PaginationResponse page1SingleSortDesc = testInterface.getSessionsForCustomer(customerId_1, null, null, Collections.singletonList(new ColumnAndSort("macAddress", SortOrder.desc)), context); assertEquals(10, page1SingleSortDesc.getItems().size()); - List expectedPage1SingleSortDescStrings = new ArrayList< >(Arrays.asList(new String[]{"qr_49", "qr_48", "qr_47", "qr_46", "qr_45", "qr_44", "qr_43", "qr_42", "qr_41", "qr_40" })); + List expectedPage1SingleSortDescStrings = getClientSessionPagination_expectedPage1SingleSortDescStrings(); List actualPage1SingleSortDescStrings = new ArrayList<>(); page1SingleSortDesc.getItems().stream().forEach( ce -> actualPage1SingleSortDescStrings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) ); @@ -1021,6 +1054,19 @@ public abstract class BaseClientDatastoreTest { createdListExtra.forEach(c -> testInterface.deleteSession(c.getCustomerId(), c.getEquipmentId(), c.getMacAddress())); } + protected List getClientSessionPagination_expectedPage1EmptySortStrings(){ + return new ArrayList<>(Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" })); + } + + protected List getClientSessionPagination_expectedPage3Strings(){ + return new ArrayList<>(Arrays.asList(new String[]{"qr_20", "qr_21", "qr_22", "qr_23", "qr_24", "qr_25", "qr_26", "qr_27", "qr_28", "qr_29" })); + } + + protected List getClientSessionPagination_expectedPage1SingleSortDescStrings() { + return new ArrayList<>(Arrays.asList(new String[]{"qr_49", "qr_48", "qr_47", "qr_46", "qr_45", "qr_44", "qr_43", "qr_42", "qr_41", "qr_40" })); + } + + protected ClientSession createClientSessionObject() { ClientSession result = new ClientSession(); long nextId = testSequence.getAndIncrement(); diff --git a/routing-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/routing/datastore/cassandra/RoutingDAO.java b/routing-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/routing/datastore/cassandra/RoutingDAO.java index 1e6447bc..23afb867 100644 --- a/routing-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/routing/datastore/cassandra/RoutingDAO.java +++ b/routing-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/routing/datastore/cassandra/RoutingDAO.java @@ -406,6 +406,15 @@ public class RoutingDAO { // startAfterItem is not used in Cassandra datastores, set it to null ret.getContext().setStartAfterItem(null); + //in cassandra we will rely only on nextPagingState to set the lastPage indicator + ret.getContext().setLastPage(false); + + if(nextPagingState == null) { + //in cassandra, if there are no more pages available, the pagingState is returned as null by the driver + //this overrides all other heuristics related to guessing the indication of the last page + ret.getContext().setLastPage(true); + } + return ret; } diff --git a/routing-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/routing/datastore/cassandra/RoutingDatastoreCassandraTests.java b/routing-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/routing/datastore/cassandra/RoutingDatastoreCassandraTests.java index c01b2bb9..3d089a6d 100644 --- a/routing-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/routing/datastore/cassandra/RoutingDatastoreCassandraTests.java +++ b/routing-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/routing/datastore/cassandra/RoutingDatastoreCassandraTests.java @@ -1,31 +1,20 @@ package com.telecominfraproject.wlan.routing.datastore.cassandra; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import org.junit.Ignore; -import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.context.annotation.Import; import org.springframework.test.context.junit4.SpringRunner; -import com.telecominfraproject.wlan.core.model.pagination.ColumnAndSort; import com.telecominfraproject.wlan.core.model.pagination.PaginationContext; -import com.telecominfraproject.wlan.core.model.pagination.PaginationResponse; -import com.telecominfraproject.wlan.core.model.pagination.SortOrder; -import com.telecominfraproject.wlan.core.model.service.GatewayType; import com.telecominfraproject.wlan.core.server.cassandra.BaseCassandraDataSource; import com.telecominfraproject.wlan.core.server.cassandra.test.BaseCassandraTest; import com.telecominfraproject.wlan.routing.datastore.BaseRoutingDatastoreTest; -import com.telecominfraproject.wlan.routing.models.EquipmentGatewayRecord; import com.telecominfraproject.wlan.routing.models.EquipmentRoutingRecord; /** @@ -38,120 +27,26 @@ import com.telecominfraproject.wlan.routing.models.EquipmentRoutingRecord; @Import(value = { RoutingDatastoreCassandra.class, RoutingDAO.class, GatewayDAO.class, BaseCassandraTest.Config.class, BaseCassandraDataSource.class }) @Ignore("Ignore Cassandra Tests until we can set up a cassandra cluster for the integration testing") public class RoutingDatastoreCassandraTests extends BaseRoutingDatastoreTest { - - @Test - public void testRoutingPagination() - { - //create 100 Routings - EquipmentRoutingRecord mdl; - int customerId_1 = (int) testSequence.incrementAndGet(); - int customerId_2 = (int) testSequence.incrementAndGet(); - - EquipmentGatewayRecord gateway = new EquipmentGatewayRecord(); - gateway.setGatewayType(GatewayType.CEGW); - gateway.setHostname("test-hostname"+testSequence.incrementAndGet()); - gateway.setIpAddr("127.0.0.1"); - gateway.setPort(4242); - gateway = testInterface.registerGateway(gateway); - - List createdRecords = new ArrayList<>(); - - long eqId = 0; - - for(int i = 0; i< 50; i++){ - mdl = new EquipmentRoutingRecord(); - mdl.setCustomerId(customerId_1); - mdl.setGatewayId(gateway.getId()); - mdl.setEquipmentId(eqId); - - eqId++; - mdl = testInterface.create(mdl); - createdRecords.add(mdl); - } - - for(int i = 0; i< 50; i++){ - mdl = new EquipmentRoutingRecord(); - mdl.setCustomerId(customerId_2); - mdl.setGatewayId(gateway.getId()); - mdl.setEquipmentId(eqId); - - eqId++; - mdl = testInterface.create(mdl); - createdRecords.add(mdl); - } - - //paginate over Routings - - List sortBy = new ArrayList<>(); - //Note: sort order is ignored by cassandra - //sortBy.addAll(Arrays.asList(new ColumnAndSort("equipmentId"))); - - PaginationContext context = new PaginationContext<>(10); - PaginationResponse page1 = testInterface.getForCustomer(customerId_1, sortBy, context); - PaginationResponse page2 = testInterface.getForCustomer(customerId_1, sortBy, page1.getContext()); - PaginationResponse page3 = testInterface.getForCustomer(customerId_1, sortBy, page2.getContext()); - PaginationResponse page4 = testInterface.getForCustomer(customerId_1, sortBy, page3.getContext()); - PaginationResponse page5 = testInterface.getForCustomer(customerId_1, sortBy, page4.getContext()); - PaginationResponse page6 = testInterface.getForCustomer(customerId_1, sortBy, page5.getContext()); - PaginationResponse page7 = testInterface.getForCustomer(customerId_1, sortBy, page6.getContext()); - - //verify returned pages - assertEquals(10, page1.getItems().size()); - assertEquals(10, page2.getItems().size()); - assertEquals(10, page3.getItems().size()); - assertEquals(10, page4.getItems().size()); - assertEquals(10, page5.getItems().size()); - - page1.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page2.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page3.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page4.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page5.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - - assertEquals(0, page6.getItems().size()); - assertEquals(0, page7.getItems().size()); - - assertFalse(page1.getContext().isLastPage()); - assertFalse(page2.getContext().isLastPage()); - assertFalse(page3.getContext().isLastPage()); - assertFalse(page4.getContext().isLastPage()); - assertFalse(page5.getContext().isLastPage()); - - assertTrue(page6.getContext().isLastPage()); - assertTrue(page7.getContext().isLastPage()); - - - //test first page of the results with empty sort order -> default sort order (by Id ascending) -> the sort order is ignored by cassandra datastore - PaginationResponse page1EmptySort = testInterface.getForCustomer(customerId_1, Collections.emptyList(), context); - assertEquals(10, page1EmptySort.getItems().size()); - - List actualPage1EmptySortLongs = new ArrayList<>(); - page1EmptySort.getItems().stream().forEach( ce -> actualPage1EmptySortLongs.add( ce.getEquipmentId()) ); - - - //test first page of the results with null sort order -> default sort order (by Id ascending) -> the sort order is ignored by cassandra datastore - PaginationResponse page1NullSort = testInterface.getForCustomer(customerId_1, null, context); - assertEquals(10, page1NullSort.getItems().size()); - - List expectedPage1NullSortLongs = new ArrayList<>(actualPage1EmptySortLongs); - List actualPage1NullSortLongs = new ArrayList<>(); - page1NullSort.getItems().stream().forEach( ce -> actualPage1NullSortLongs.add( ce.getEquipmentId()) ); - - assertEquals(expectedPage1NullSortLongs, actualPage1NullSortLongs); - - - //test first page of the results with sort descending order by a gatewayId property -> the sort order is ignored by cassandra datastore - PaginationResponse page1SingleSortDesc = testInterface.getForCustomer(customerId_1, Collections.singletonList(new ColumnAndSort("equipmentId", SortOrder.desc)), context); - assertEquals(10, page1SingleSortDesc.getItems().size()); - - List expectedPage1SingleSortDescLongs = new ArrayList<>(actualPage1EmptySortLongs); - List actualPage1SingleSortDescLongs = new ArrayList<>(); - page1SingleSortDesc.getItems().stream().forEach( ce -> actualPage1SingleSortDescLongs.add( ce.getEquipmentId()) ); - - assertEquals(expectedPage1SingleSortDescLongs, actualPage1SingleSortDescLongs); - - createdRecords.forEach(r -> testInterface.delete(r.getId())); - testInterface.deleteGateway(gateway.getId()); - + + @Override + protected List getRoutingPagination_expectedPage1SingleSortDescLongs(int customerId){ + return getRoutingPagination_expectedPage1EmptySortLongs(customerId); } + + @Override + protected List getRoutingPagination_expectedPage1EmptySortLongs(int customerId){ + + List actualPage1EmptySortLongs = new ArrayList<>(); + testInterface + .getForCustomer(customerId, Collections.emptyList(), new PaginationContext(10)) + .getItems().forEach(ce -> actualPage1EmptySortLongs.add(ce.getEquipmentId())); + + return actualPage1EmptySortLongs; + } + + @Override + protected List getRoutingPagination_expectedPage3Longs(){ + return Collections.emptyList(); + } + } diff --git a/routing-datastore-cassandra/src/test/resources/test-commands.cql b/routing-datastore-cassandra/src/test/resources/test-commands.cql index 7c3fb811..29ded08b 100644 --- a/routing-datastore-cassandra/src/test/resources/test-commands.cql +++ b/routing-datastore-cassandra/src/test/resources/test-commands.cql @@ -53,3 +53,9 @@ delete from equipment_routing where id = 1; select * from equipment_routing where customerId = 1; select * from equipment_routing where equipmentId = 1; + +--- +--- Clean up data +--- +truncate table equipment_gateway; +truncate table equipment_routing; diff --git a/routing-datastore-common-test/src/main/java/com/telecominfraproject/wlan/routing/datastore/BaseRoutingDatastoreTest.java b/routing-datastore-common-test/src/main/java/com/telecominfraproject/wlan/routing/datastore/BaseRoutingDatastoreTest.java index 0ab0179c..f6ae6980 100644 --- a/routing-datastore-common-test/src/main/java/com/telecominfraproject/wlan/routing/datastore/BaseRoutingDatastoreTest.java +++ b/routing-datastore-common-test/src/main/java/com/telecominfraproject/wlan/routing/datastore/BaseRoutingDatastoreTest.java @@ -260,18 +260,21 @@ public abstract class BaseRoutingDatastoreTest { assertTrue(page6.getContext().isLastPage()); assertTrue(page7.getContext().isLastPage()); - List expectedPage3Longs = new ArrayList< >(Arrays.asList(new Long[]{20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L })); + List expectedPage3Longs = getRoutingPagination_expectedPage3Longs(); List actualPage3Longs = new ArrayList<>(); page3.getItems().stream().forEach( ce -> actualPage3Longs.add( ce.getEquipmentId()) ); - assertEquals(expectedPage3Longs, actualPage3Longs); + if(!expectedPage3Longs.isEmpty()) { + //cassandra datastore does not orded the results the way other datastores do, so we'll skip this check for it + assertEquals(expectedPage3Longs, actualPage3Longs); + } //test first page of the results with empty sort order -> default sort order (by Id ascending) PaginationResponse page1EmptySort = testInterface.getForCustomer(customerId_1, Collections.emptyList(), context); assertEquals(10, page1EmptySort.getItems().size()); - List expectedPage1EmptySortLongs = new ArrayList<>(Arrays.asList(new Long[]{0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L })); + List expectedPage1EmptySortLongs = getRoutingPagination_expectedPage1EmptySortLongs(customerId_1); List actualPage1EmptySortLongs = new ArrayList<>(); page1EmptySort.getItems().stream().forEach( ce -> actualPage1EmptySortLongs.add( ce.getEquipmentId()) ); @@ -281,7 +284,7 @@ public abstract class BaseRoutingDatastoreTest { PaginationResponse page1NullSort = testInterface.getForCustomer(customerId_1, null, context); assertEquals(10, page1NullSort.getItems().size()); - List expectedPage1NullSortLongs = new ArrayList<>(Arrays.asList(new Long[]{0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L })); + List expectedPage1NullSortLongs = expectedPage1EmptySortLongs; List actualPage1NullSortLongs = new ArrayList<>(); page1NullSort.getItems().stream().forEach( ce -> actualPage1NullSortLongs.add( ce.getEquipmentId()) ); @@ -292,7 +295,7 @@ public abstract class BaseRoutingDatastoreTest { PaginationResponse page1SingleSortDesc = testInterface.getForCustomer(customerId_1, Collections.singletonList(new ColumnAndSort("equipmentId", SortOrder.desc)), context); assertEquals(10, page1SingleSortDesc.getItems().size()); - List expectedPage1SingleSortDescLongs = new ArrayList< >(Arrays.asList(new Long[]{ 49L, 48L, 47L, 46L, 45L, 44L, 43L, 42L, 41L, 40L })); + List expectedPage1SingleSortDescLongs = getRoutingPagination_expectedPage1SingleSortDescLongs(customerId_1); List actualPage1SingleSortDescLongs = new ArrayList<>(); page1SingleSortDesc.getItems().stream().forEach( ce -> actualPage1SingleSortDescLongs.add( ce.getEquipmentId()) ); @@ -303,6 +306,19 @@ public abstract class BaseRoutingDatastoreTest { } + protected List getRoutingPagination_expectedPage1SingleSortDescLongs(int customerId){ + return Arrays.asList(new Long[]{ 49L, 48L, 47L, 46L, 45L, 44L, 43L, 42L, 41L, 40L }); + } + + protected List getRoutingPagination_expectedPage1EmptySortLongs(int customerId){ + return Arrays.asList(new Long[]{0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L }); + } + + protected List getRoutingPagination_expectedPage3Longs(){ + return Arrays.asList(new Long[]{20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L }); + } + + @Test public void testGatewayCRUD(){ EquipmentGatewayRecord gateway = new EquipmentGatewayRecord(); diff --git a/service-metric-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/servicemetric/datastore/cassandra/ServiceMetricDatastoreCassandra.java b/service-metric-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/servicemetric/datastore/cassandra/ServiceMetricDatastoreCassandra.java index 28579957..9058edc6 100644 --- a/service-metric-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/servicemetric/datastore/cassandra/ServiceMetricDatastoreCassandra.java +++ b/service-metric-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/servicemetric/datastore/cassandra/ServiceMetricDatastoreCassandra.java @@ -913,12 +913,9 @@ public class ServiceMetricDatastoreCassandra implements ServiceMetricDatastore { // startAfterItem is not used in Cassandra datastores, set it to null ret.getContext().setStartAfterItem(null); - if(filterOptions == FilterOptions.location && !pageItems.isEmpty()) { - //when using client-side filtering for locations we may be hitting the situations when current page has less than max items, but it is not the last page - //since we're skipping the empty pages when doing client-side filtering, we can use final pageItems.isEmpty() as an indicator of the last page. - ret.getContext().setLastPage(false); - } - + //in cassandra we will rely only on nextPagingState to set the lastPage indicator + ret.getContext().setLastPage(false); + if(pagingState == null) { //in cassandra, if there are no more pages available, the pagingState is returned as null by the driver //this overrides all other heuristics related to guessing the indication of the last page diff --git a/service-metric-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/servicemetric/datastore/cassandra/ServiceMetricDatastoreCassandraTests.java b/service-metric-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/servicemetric/datastore/cassandra/ServiceMetricDatastoreCassandraTests.java index ab3c5442..ac1747c2 100644 --- a/service-metric-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/servicemetric/datastore/cassandra/ServiceMetricDatastoreCassandraTests.java +++ b/service-metric-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/servicemetric/datastore/cassandra/ServiceMetricDatastoreCassandraTests.java @@ -1,33 +1,18 @@ package com.telecominfraproject.wlan.servicemetric.datastore.cassandra; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; import org.junit.Ignore; -import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.context.annotation.Import; import org.springframework.test.context.junit4.SpringRunner; -import com.telecominfraproject.wlan.core.model.pagination.ColumnAndSort; -import com.telecominfraproject.wlan.core.model.pagination.PaginationContext; -import com.telecominfraproject.wlan.core.model.pagination.PaginationResponse; -import com.telecominfraproject.wlan.core.model.pagination.SortOrder; import com.telecominfraproject.wlan.core.server.cassandra.BaseCassandraDataSource; import com.telecominfraproject.wlan.core.server.cassandra.test.BaseCassandraTest; -import com.telecominfraproject.wlan.servicemetric.client.models.ClientMetrics; import com.telecominfraproject.wlan.servicemetric.datastore.BaseServiceMetricDatastoreTest; -import com.telecominfraproject.wlan.servicemetric.models.ServiceMetric; /** * @author dtoptygin @@ -39,157 +24,10 @@ import com.telecominfraproject.wlan.servicemetric.models.ServiceMetric; @Import(value = { ServiceMetricDatastoreCassandra.class, BaseCassandraTest.Config.class, BaseCassandraDataSource.class }) @Ignore("Ignore Cassandra Tests until we can set up a cassandra cluster for the integration testing") public class ServiceMetricDatastoreCassandraTests extends BaseServiceMetricDatastoreTest { - - //verify returned data and sort options - @Test - public void testPagination() { - - int customerId_1 = (int) testSequence.incrementAndGet(); - int customerId_2 = (int) testSequence.incrementAndGet(); - long baseTimestamp = System.currentTimeMillis(); + @Override + protected List getPagination_expectedPage1SingleSortDescStrings(){ + return Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" }); + } - long apNameIdx = 0; - - long fromTime = 0; - long toTime = baseTimestamp; - - //create 150 Service metrics - - Set used_equipmentIds = new HashSet<>(); - - //metrics to be tested - for(int i = 0; i< 50; i++){ - ServiceMetric serviceMetric = new ServiceMetric(); - serviceMetric.setCustomerId(customerId_1); - serviceMetric.setEquipmentId(testSequence.incrementAndGet()); - serviceMetric.setClientMac(testSequence.incrementAndGet()); - serviceMetric.setCreatedTimestamp(baseTimestamp - 100000 + testSequence.incrementAndGet()); - - ClientMetrics details2 = new ClientMetrics(); - details2.setClassificationName("qr_"+apNameIdx); - serviceMetric.setDetails(details2); - - apNameIdx++; - - testInterface.create(serviceMetric); - used_equipmentIds.add(serviceMetric.getEquipmentId()); - } - - //metrics outside the target time - for(int i = 0; i< 50; i++){ - ServiceMetric serviceMetric = new ServiceMetric(); - serviceMetric.setCustomerId(customerId_1); - serviceMetric.setEquipmentId(testSequence.incrementAndGet()); - serviceMetric.setClientMac(testSequence.incrementAndGet()); - serviceMetric.setCreatedTimestamp(baseTimestamp + testSequence.incrementAndGet()); - - ClientMetrics details2 = new ClientMetrics(); - details2.setClassificationName("qr_"+apNameIdx); - serviceMetric.setDetails(details2); - - apNameIdx++; - - testInterface.create(serviceMetric); - used_equipmentIds.add(serviceMetric.getEquipmentId()); - } - - //metrics for another customer - for(int i = 0; i< 50; i++){ - ServiceMetric serviceMetric = new ServiceMetric(); - serviceMetric.setCustomerId(customerId_2); - serviceMetric.setEquipmentId(testSequence.incrementAndGet()); - serviceMetric.setClientMac(testSequence.incrementAndGet()); - serviceMetric.setCreatedTimestamp(baseTimestamp - 100000 + testSequence.incrementAndGet()); - - ClientMetrics details2 = new ClientMetrics(); - details2.setClassificationName("qr_"+apNameIdx); - serviceMetric.setDetails(details2); - - apNameIdx++; - - testInterface.create(serviceMetric); - used_equipmentIds.add(serviceMetric.getEquipmentId()); - } - - //paginate over Metrics - - List sortBy = new ArrayList<>(); - sortBy.addAll(Arrays.asList(new ColumnAndSort("equipmentId"))); - - PaginationContext context = new PaginationContext<>(10); - PaginationResponse page1 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, context); - PaginationResponse page2 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page1.getContext()); - PaginationResponse page3 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page2.getContext()); - PaginationResponse page4 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page3.getContext()); - PaginationResponse page5 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page4.getContext()); - PaginationResponse page6 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page5.getContext()); - PaginationResponse page7 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page6.getContext()); - - //verify returned pages - assertEquals(10, page1.getItems().size()); - assertEquals(10, page2.getItems().size()); - assertEquals(10, page3.getItems().size()); - assertEquals(10, page4.getItems().size()); - assertEquals(10, page5.getItems().size()); - - page1.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page2.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page3.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page4.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page5.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - - assertEquals(0, page6.getItems().size()); - assertEquals(0, page7.getItems().size()); - - assertFalse(page1.getContext().isLastPage()); - assertFalse(page2.getContext().isLastPage()); - assertFalse(page3.getContext().isLastPage()); - assertFalse(page4.getContext().isLastPage()); - assertFalse(page5.getContext().isLastPage()); - - assertTrue(page6.getContext().isLastPage()); - assertTrue(page7.getContext().isLastPage()); - - List expectedPage3Strings = new ArrayList<>(Arrays.asList(new String[]{"qr_20", "qr_21", "qr_22", "qr_23", "qr_24", "qr_25", "qr_26", "qr_27", "qr_28", "qr_29" })); - List actualPage3Strings = new ArrayList<>(); - page3.getItems().stream().forEach( ce -> actualPage3Strings.add(((ClientMetrics) ce.getDetails()).getClassificationName()) ); - - assertEquals(expectedPage3Strings, actualPage3Strings); - - //test first page of the results with empty sort order -> default sort order (by createdTimestamp ascending) - PaginationResponse page1EmptySort = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, Collections.emptyList(), context); - assertEquals(10, page1EmptySort.getItems().size()); - - List expectedPage1EmptySortStrings = new ArrayList<>(Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" })); - List actualPage1EmptySortStrings = new ArrayList<>(); - page1EmptySort.getItems().stream().forEach( ce -> actualPage1EmptySortStrings.add(((ClientMetrics) ce.getDetails()).getClassificationName() ) ); - - assertEquals(expectedPage1EmptySortStrings, actualPage1EmptySortStrings); - - //test first page of the results with null sort order -> default sort order (by createdTimestamp ascending) - PaginationResponse page1NullSort = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, null, context); - assertEquals(10, page1NullSort.getItems().size()); - - List expectedPage1NullSortStrings = new ArrayList<>(Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" })); - List actualPage1NullSortStrings = new ArrayList<>(); - page1NullSort.getItems().stream().forEach( ce -> actualPage1NullSortStrings.add(((ClientMetrics) ce.getDetails()).getClassificationName() ) ); - - assertEquals(expectedPage1NullSortStrings, actualPage1NullSortStrings); - - - //test first page of the results with sort descending order by a equipmentId property -> cassandra ignores supplied sort order - PaginationResponse page1SingleSortDesc = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, Collections.singletonList(new ColumnAndSort("equipmentId", SortOrder.desc)), context); - assertEquals(10, page1SingleSortDesc.getItems().size()); - - List expectedPage1SingleSortDescStrings = new ArrayList< >(Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" })); - List actualPage1SingleSortDescStrings = new ArrayList<>(); - page1SingleSortDesc.getItems().stream().forEach( ce -> actualPage1SingleSortDescStrings.add(((ClientMetrics) ce.getDetails()).getClassificationName() ) ); - - assertEquals(expectedPage1SingleSortDescStrings, actualPage1SingleSortDescStrings); - - used_equipmentIds.forEach(eqId -> testInterface.delete(customerId_1, eqId, System.currentTimeMillis())); - used_equipmentIds.forEach(eqId -> testInterface.delete(customerId_2, eqId, System.currentTimeMillis())); - - } } diff --git a/service-metric-datastore-common-test/src/main/java/com/telecominfraproject/wlan/servicemetric/datastore/BaseServiceMetricDatastoreTest.java b/service-metric-datastore-common-test/src/main/java/com/telecominfraproject/wlan/servicemetric/datastore/BaseServiceMetricDatastoreTest.java index a956bcde..08d5a23b 100644 --- a/service-metric-datastore-common-test/src/main/java/com/telecominfraproject/wlan/servicemetric/datastore/BaseServiceMetricDatastoreTest.java +++ b/service-metric-datastore-common-test/src/main/java/com/telecominfraproject/wlan/servicemetric/datastore/BaseServiceMetricDatastoreTest.java @@ -231,7 +231,7 @@ public abstract class BaseServiceMetricDatastoreTest { PaginationResponse page1SingleSortDesc = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, Collections.singletonList(new ColumnAndSort("equipmentId", SortOrder.desc)), context); assertEquals(10, page1SingleSortDesc.getItems().size()); - List expectedPage1SingleSortDescStrings = new ArrayList< >(Arrays.asList(new String[]{"qr_49", "qr_48", "qr_47", "qr_46", "qr_45", "qr_44", "qr_43", "qr_42", "qr_41", "qr_40" })); + List expectedPage1SingleSortDescStrings = getPagination_expectedPage1SingleSortDescStrings(); List actualPage1SingleSortDescStrings = new ArrayList<>(); page1SingleSortDesc.getItems().stream().forEach( ce -> actualPage1SingleSortDescStrings.add(((ClientMetrics) ce.getDetails()).getClassificationName() ) ); @@ -242,6 +242,9 @@ public abstract class BaseServiceMetricDatastoreTest { } + protected List getPagination_expectedPage1SingleSortDescStrings(){ + return Arrays.asList(new String[]{"qr_49", "qr_48", "qr_47", "qr_46", "qr_45", "qr_44", "qr_43", "qr_42", "qr_41", "qr_40" }); + } @Test public void testPaginationWithFilters() { diff --git a/status-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/status/datastore/cassandra/StatusDatastoreCassandra.java b/status-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/status/datastore/cassandra/StatusDatastoreCassandra.java index 1843eecd..de016077 100644 --- a/status-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/status/datastore/cassandra/StatusDatastoreCassandra.java +++ b/status-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/status/datastore/cassandra/StatusDatastoreCassandra.java @@ -552,6 +552,15 @@ public class StatusDatastoreCassandra implements StatusDatastore { // startAfterItem is not used in Cassandra datastores, set it to null ret.getContext().setStartAfterItem(null); + //in cassandra we will rely only on nextPagingState to set the lastPage indicator + ret.getContext().setLastPage(false); + + if(nextPagingState == null) { + //in cassandra, if there are no more pages available, the pagingState is returned as null by the driver + //this overrides all other heuristics related to guessing the indication of the last page + ret.getContext().setLastPage(true); + } + return ret; } diff --git a/status-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/status/datastore/cassandra/StatusDatastoreCassandraTests.java b/status-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/status/datastore/cassandra/StatusDatastoreCassandraTests.java index 9cd64f80..ae852d41 100644 --- a/status-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/status/datastore/cassandra/StatusDatastoreCassandraTests.java +++ b/status-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/status/datastore/cassandra/StatusDatastoreCassandraTests.java @@ -1,31 +1,18 @@ package com.telecominfraproject.wlan.status.datastore.cassandra; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.junit.Ignore; -import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.context.annotation.Import; import org.springframework.test.context.junit4.SpringRunner; -import com.telecominfraproject.wlan.core.model.pagination.ColumnAndSort; -import com.telecominfraproject.wlan.core.model.pagination.PaginationContext; -import com.telecominfraproject.wlan.core.model.pagination.PaginationResponse; -import com.telecominfraproject.wlan.core.model.pagination.SortOrder; import com.telecominfraproject.wlan.core.server.cassandra.BaseCassandraDataSource; import com.telecominfraproject.wlan.core.server.cassandra.test.BaseCassandraTest; import com.telecominfraproject.wlan.status.datastore.BaseStatusDatastoreTest; -import com.telecominfraproject.wlan.status.equipment.models.EquipmentAdminStatusData; -import com.telecominfraproject.wlan.status.models.Status; /** * @author dtoptygin @@ -47,124 +34,21 @@ public class StatusDatastoreCassandraTests extends BaseStatusDatastoreTest { // // See https://thelastpickle.com/blog/2016/07/27/about-deletes-and-tombstones.html for more details - @Test @Override - //Cassandra has limited support for sort options, reflect it in the test - public void testStatusPagination() - { - //create 100 Statuses - Status mdl; - int customerId_1 = (int) testSequence.incrementAndGet(); - int customerId_2 = (int) testSequence.incrementAndGet(); - - List allCreatedStatuses = new ArrayList<>(); - - int apNameIdx = 0; - - for(int i = 0; i< 50; i++){ - mdl = createStatusObject(); - mdl.setCustomerId(customerId_1); - ((EquipmentAdminStatusData) mdl.getDetails()).setStatusMessage("qr_"+apNameIdx); - - apNameIdx++; - mdl = testInterface.update(mdl); - allCreatedStatuses.add(mdl); - } - - for(int i = 0; i< 50; i++){ - mdl = createStatusObject(); - mdl.setCustomerId(customerId_2); - ((EquipmentAdminStatusData) mdl.getDetails()).setStatusMessage("qr_"+apNameIdx); - - apNameIdx++; - mdl = testInterface.update(mdl); - allCreatedStatuses.add(mdl); - } - - //paginate over Statuses - - List sortBy = new ArrayList<>(); - //NOTE: sort order is ignored by the Cassandra DAO - sortBy.addAll(Arrays.asList(new ColumnAndSort("equipmentId"))); - - PaginationContext context = new PaginationContext<>(10); - PaginationResponse page1 = testInterface.getForCustomer(customerId_1, sortBy, context); - PaginationResponse page2 = testInterface.getForCustomer(customerId_1, sortBy, page1.getContext()); - PaginationResponse page3 = testInterface.getForCustomer(customerId_1, sortBy, page2.getContext()); - PaginationResponse page4 = testInterface.getForCustomer(customerId_1, sortBy, page3.getContext()); - PaginationResponse page5 = testInterface.getForCustomer(customerId_1, sortBy, page4.getContext()); - PaginationResponse page6 = testInterface.getForCustomer(customerId_1, sortBy, page5.getContext()); - PaginationResponse page7 = testInterface.getForCustomer(customerId_1, sortBy, page6.getContext()); - - //verify returned pages - assertEquals(10, page1.getItems().size()); - assertEquals(10, page2.getItems().size()); - assertEquals(10, page3.getItems().size()); - assertEquals(10, page4.getItems().size()); - assertEquals(10, page5.getItems().size()); - - page1.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page2.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page3.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page4.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page5.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - - assertEquals(0, page6.getItems().size()); - assertEquals(0, page7.getItems().size()); - - assertFalse(page1.getContext().isLastPage()); - assertFalse(page2.getContext().isLastPage()); - assertFalse(page3.getContext().isLastPage()); - assertFalse(page4.getContext().isLastPage()); - assertFalse(page5.getContext().isLastPage()); - - assertTrue(page6.getContext().isLastPage()); - assertTrue(page7.getContext().isLastPage()); - - //NOTE: because sort options are ignored by cassandra dao, the results come in weird but stable order: - List expectedPage3Strings = new ArrayList<>(Arrays.asList(new String[]{"qr_49", "qr_45", "qr_8", "qr_33", "qr_7", "qr_35", "qr_22", "qr_11", "qr_16", "qr_1" })); - List actualPage3Strings = new ArrayList<>(); - page3.getItems().stream().forEach( ce -> actualPage3Strings.add(((EquipmentAdminStatusData) ce.getDetails()).getStatusMessage()) ); - - assertEquals(expectedPage3Strings, actualPage3Strings); - - - //test first page of the results with empty sort order -> default sort order (by Id ascending) - PaginationResponse page1EmptySort = testInterface.getForCustomer(customerId_1, Collections.emptyList(), context); - assertEquals(10, page1EmptySort.getItems().size()); - - //NOTE: because sort options are ignored by cassandra dao, the results come in weird but stable order: - List expectedPage1EmptySortStrings = new ArrayList<>(Arrays.asList(new String[]{"qr_3", "qr_13", "qr_38", "qr_40", "qr_44", "qr_17", "qr_41", "qr_39", "qr_19", "qr_34" })); - List actualPage1EmptySortStrings = new ArrayList<>(); - page1EmptySort.getItems().stream().forEach( ce -> actualPage1EmptySortStrings.add(((EquipmentAdminStatusData) ce.getDetails()).getStatusMessage()) ); - - assertEquals(expectedPage1EmptySortStrings, actualPage1EmptySortStrings); - - //test first page of the results with null sort order -> default sort order (by Id ascending) - PaginationResponse page1NullSort = testInterface.getForCustomer(customerId_1, null, context); - assertEquals(10, page1NullSort.getItems().size()); - - //NOTE: because sort options are ignored by cassandra dao, the results come in weird but stable order: - List expectedPage1NullSortStrings = new ArrayList<>(Arrays.asList(new String[]{"qr_3", "qr_13", "qr_38", "qr_40", "qr_44", "qr_17", "qr_41", "qr_39", "qr_19", "qr_34" })); - List actualPage1NullSortStrings = new ArrayList<>(); - page1NullSort.getItems().stream().forEach( ce -> actualPage1NullSortStrings.add(((EquipmentAdminStatusData) ce.getDetails()).getStatusMessage()) ); - - assertEquals(expectedPage1NullSortStrings, actualPage1NullSortStrings); - - - //test first page of the results with sort descending order by a equipmentId property - PaginationResponse page1SingleSortDesc = testInterface.getForCustomer(customerId_1, Collections.singletonList(new ColumnAndSort("equipmentId", SortOrder.desc)), context); - assertEquals(10, page1SingleSortDesc.getItems().size()); - - //NOTE: because sort options are ignored by cassandra dao, the results come in weird but stable order: - List expectedPage1SingleSortDescStrings = new ArrayList<>(Arrays.asList(new String[]{"qr_3", "qr_13", "qr_38", "qr_40", "qr_44", "qr_17", "qr_41", "qr_39", "qr_19", "qr_34" })); - List actualPage1SingleSortDescStrings = new ArrayList<>(); - page1SingleSortDesc.getItems().stream().forEach( ce -> actualPage1SingleSortDescStrings.add(((EquipmentAdminStatusData) ce.getDetails()).getStatusMessage()) ); - - assertEquals(expectedPage1SingleSortDescStrings, actualPage1SingleSortDescStrings); - - //delete - allCreatedStatuses.forEach(s -> testInterface.delete(s.getCustomerId(), s.getEquipmentId())); - + protected List getStatusPagination_expectedPage1SingleSortDescStrings(){ + return getStatusPagination_expectedPage1EmptySortStrings(); } + + + @Override + protected List getStatusPagination_expectedPage1EmptySortStrings(){ + return Arrays.asList(new String[]{"qr_3", "qr_13", "qr_38", "qr_40", "qr_44", "qr_17", "qr_41", "qr_39", "qr_19", "qr_34" }); + } + + + @Override + protected List getStatusPagination_expectedPage3Strings(){ + return Arrays.asList(new String[]{"qr_49", "qr_45", "qr_8", "qr_33", "qr_7", "qr_35", "qr_22", "qr_11", "qr_16", "qr_1" }); + } + } diff --git a/status-datastore-common-test/src/main/java/com/telecominfraproject/wlan/status/datastore/BaseStatusDatastoreTest.java b/status-datastore-common-test/src/main/java/com/telecominfraproject/wlan/status/datastore/BaseStatusDatastoreTest.java index 3722d6c1..22847a1b 100644 --- a/status-datastore-common-test/src/main/java/com/telecominfraproject/wlan/status/datastore/BaseStatusDatastoreTest.java +++ b/status-datastore-common-test/src/main/java/com/telecominfraproject/wlan/status/datastore/BaseStatusDatastoreTest.java @@ -236,7 +236,7 @@ public abstract class BaseStatusDatastoreTest { assertTrue(page6.getContext().isLastPage()); assertTrue(page7.getContext().isLastPage()); - List expectedPage3Strings = new ArrayList< >(Arrays.asList(new String[]{"qr_20", "qr_21", "qr_22", "qr_23", "qr_24", "qr_25", "qr_26", "qr_27", "qr_28", "qr_29" })); + List expectedPage3Strings = getStatusPagination_expectedPage3Strings(); List actualPage3Strings = new ArrayList<>(); page3.getItems().stream().forEach( ce -> actualPage3Strings.add(((EquipmentAdminStatusData) ce.getDetails()).getStatusMessage()) ); @@ -254,7 +254,7 @@ public abstract class BaseStatusDatastoreTest { PaginationResponse page1EmptySort = testInterface.getForCustomer(customerId_1, Collections.emptyList(), context); assertEquals(10, page1EmptySort.getItems().size()); - List expectedPage1EmptySortStrings = new ArrayList<>(Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" })); + List expectedPage1EmptySortStrings = getStatusPagination_expectedPage1EmptySortStrings(); List actualPage1EmptySortStrings = new ArrayList<>(); page1EmptySort.getItems().stream().forEach( ce -> actualPage1EmptySortStrings.add(((EquipmentAdminStatusData) ce.getDetails()).getStatusMessage()) ); @@ -264,7 +264,7 @@ public abstract class BaseStatusDatastoreTest { PaginationResponse page1NullSort = testInterface.getForCustomer(customerId_1, null, context); assertEquals(10, page1NullSort.getItems().size()); - List expectedPage1NullSortStrings = new ArrayList<>(Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" })); + List expectedPage1NullSortStrings = expectedPage1EmptySortStrings; List actualPage1NullSortStrings = new ArrayList<>(); page1NullSort.getItems().stream().forEach( ce -> actualPage1NullSortStrings.add(((EquipmentAdminStatusData) ce.getDetails()).getStatusMessage()) ); @@ -275,7 +275,7 @@ public abstract class BaseStatusDatastoreTest { PaginationResponse page1SingleSortDesc = testInterface.getForCustomer(customerId_1, Collections.singletonList(new ColumnAndSort("equipmentId", SortOrder.desc)), context); assertEquals(10, page1SingleSortDesc.getItems().size()); - List expectedPage1SingleSortDescStrings = new ArrayList< >(Arrays.asList(new String[]{"qr_49", "qr_48", "qr_47", "qr_46", "qr_45", "qr_44", "qr_43", "qr_42", "qr_41", "qr_40" })); + List expectedPage1SingleSortDescStrings = getStatusPagination_expectedPage1SingleSortDescStrings(); List actualPage1SingleSortDescStrings = new ArrayList<>(); page1SingleSortDesc.getItems().stream().forEach( ce -> actualPage1SingleSortDescStrings.add(((EquipmentAdminStatusData) ce.getDetails()).getStatusMessage()) ); @@ -286,6 +286,18 @@ public abstract class BaseStatusDatastoreTest { } + protected List getStatusPagination_expectedPage1SingleSortDescStrings(){ + return Arrays.asList(new String[]{"qr_49", "qr_48", "qr_47", "qr_46", "qr_45", "qr_44", "qr_43", "qr_42", "qr_41", "qr_40" }); + } + + protected List getStatusPagination_expectedPage1EmptySortStrings(){ + return Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" }); + } + + protected List getStatusPagination_expectedPage3Strings(){ + return Arrays.asList(new String[]{"qr_20", "qr_21", "qr_22", "qr_23", "qr_24", "qr_25", "qr_26", "qr_27", "qr_28", "qr_29" }); + } + @Test public void testStatusPaginationWithFilters() { @@ -349,7 +361,9 @@ public abstract class BaseStatusDatastoreTest { mdl = new Status(); mdl.setCustomerId(customerId_1); mdl.setEquipmentId(equipmentIds_1[i]); - + + allCreatedStatuses.add(mdl); + EquipmentProtocolStatusData details2 = new EquipmentProtocolStatusData(); details2.setSerialNumber("qr_"+apNameIdx); mdl.setDetails(details2); @@ -360,7 +374,9 @@ public abstract class BaseStatusDatastoreTest { mdl = new Status(); mdl.setCustomerId(customerId_1); mdl.setEquipmentId(equipmentIds_1[i]); - + + allCreatedStatuses.add(mdl); + OperatingSystemPerformance details3 = new OperatingSystemPerformance(); details3.setAvgFreeMemoryKb(apNameIdx); mdl.setDetails(details3); @@ -651,6 +667,8 @@ public abstract class BaseStatusDatastoreTest { mdl.setCustomerId(customerId_1); mdl.setEquipmentId(equipmentIds_1[i]); + allCreatedStatuses.add(mdl); + EquipmentProtocolStatusData details2 = new EquipmentProtocolStatusData(); details2.setSerialNumber("qr_"+apNameIdx); mdl.setDetails(details2); @@ -662,6 +680,8 @@ public abstract class BaseStatusDatastoreTest { mdl.setCustomerId(customerId_1); mdl.setEquipmentId(equipmentIds_1[i]); + allCreatedStatuses.add(mdl); + OperatingSystemPerformance details3 = new OperatingSystemPerformance(); details3.setAvgFreeMemoryKb(apNameIdx); mdl.setDetails(details3); diff --git a/system-event-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/systemevent/datastore/cassandra/SystemEventDatastoreCassandra.java b/system-event-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/systemevent/datastore/cassandra/SystemEventDatastoreCassandra.java index 283e76cf..0f75e4db 100644 --- a/system-event-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/systemevent/datastore/cassandra/SystemEventDatastoreCassandra.java +++ b/system-event-datastore-cassandra/src/main/java/com/telecominfraproject/wlan/systemevent/datastore/cassandra/SystemEventDatastoreCassandra.java @@ -913,13 +913,10 @@ public class SystemEventDatastoreCassandra implements SystemEventDatastore { // startAfterItem is not used in Cassandra datastores, set it to null ret.getContext().setStartAfterItem(null); - - if(filterOptions == FilterOptions.location && !pageItems.isEmpty()) { - //when using client-side filtering for locations we may be hitting the situations when current page has less than max items, but it is not the last page - //since we're skipping the empty pages when doing client-side filtering, we can use final pageItems.isEmpty() as an indicator of the last page. - ret.getContext().setLastPage(false); - } - + + //in cassandra we will rely only on nextPagingState to set the lastPage indicator + ret.getContext().setLastPage(false); + if(pagingState == null) { //in cassandra, if there are no more pages available, the pagingState is returned as null by the driver //this overrides all other heuristics related to guessing the indication of the last page diff --git a/system-event-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/systemevent/datastore/cassandra/SystemEventDatastoreCassandraTests.java b/system-event-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/systemevent/datastore/cassandra/SystemEventDatastoreCassandraTests.java index 44b64119..3716f707 100644 --- a/system-event-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/systemevent/datastore/cassandra/SystemEventDatastoreCassandraTests.java +++ b/system-event-datastore-cassandra/src/test/java/com/telecominfraproject/wlan/systemevent/datastore/cassandra/SystemEventDatastoreCassandraTests.java @@ -1,33 +1,18 @@ package com.telecominfraproject.wlan.systemevent.datastore.cassandra; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; import org.junit.Ignore; -import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.context.annotation.Import; import org.springframework.test.context.junit4.SpringRunner; -import com.telecominfraproject.wlan.core.model.pagination.ColumnAndSort; -import com.telecominfraproject.wlan.core.model.pagination.PaginationContext; -import com.telecominfraproject.wlan.core.model.pagination.PaginationResponse; -import com.telecominfraproject.wlan.core.model.pagination.SortOrder; import com.telecominfraproject.wlan.core.server.cassandra.BaseCassandraDataSource; import com.telecominfraproject.wlan.core.server.cassandra.test.BaseCassandraTest; import com.telecominfraproject.wlan.systemevent.datastore.BaseSystemEventDatastoreTest; -import com.telecominfraproject.wlan.systemevent.models.SystemEventRecord; -import com.telecominfraproject.wlan.systemevent.models.TestSystemEvent; /** * @author dtoptygin @@ -40,154 +25,9 @@ import com.telecominfraproject.wlan.systemevent.models.TestSystemEvent; @Ignore("Ignore Cassandra Tests until we can set up a cassandra cluster for the integration testing") public class SystemEventDatastoreCassandraTests extends BaseSystemEventDatastoreTest { - @Test - public void testPagination() { - - int customerId_1 = (int) testSequence.incrementAndGet(); - int customerId_2 = (int) testSequence.incrementAndGet(); + @Override + protected List getPagination_expectedPage1SingleSortDescStrings(){ + return Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" }); + } - long baseTimestamp = System.currentTimeMillis(); - - long apNameIdx = 0; - - long fromTime = 0; - long toTime = baseTimestamp; - - Set used_equipmentIds = new HashSet<>(); - - //create System events - - //events to be tested - for(int i = 0; i< 50; i++){ - - TestSystemEvent tse = new TestSystemEvent( - customerId_1, - testSequence.incrementAndGet(), - baseTimestamp - 100000 + testSequence.incrementAndGet() , - "qr_"+apNameIdx); - - SystemEventRecord systemEventRecord = new SystemEventRecord(tse); - - apNameIdx++; - - testInterface.create(systemEventRecord); - used_equipmentIds.add(systemEventRecord.getEquipmentId()); - } - - //events outside the target time - for(int i = 0; i< 50; i++){ - - TestSystemEvent tse = new TestSystemEvent( - customerId_1, - testSequence.incrementAndGet(), - baseTimestamp + testSequence.incrementAndGet() , - "qr_"+apNameIdx); - - SystemEventRecord systemEventRecord = new SystemEventRecord(tse); - - apNameIdx++; - - testInterface.create(systemEventRecord); - used_equipmentIds.add(systemEventRecord.getEquipmentId()); - } - - //events for another customer - for(int i = 0; i< 50; i++){ - - TestSystemEvent tse = new TestSystemEvent( - customerId_2, - testSequence.incrementAndGet(), - baseTimestamp - 100000 + testSequence.incrementAndGet() , - "qr_"+apNameIdx); - - SystemEventRecord systemEventRecord = new SystemEventRecord(tse); - - apNameIdx++; - - testInterface.create(systemEventRecord); - used_equipmentIds.add(systemEventRecord.getEquipmentId()); - } - - //paginate over events - - List sortBy = new ArrayList<>(); - sortBy.addAll(Arrays.asList(new ColumnAndSort("equipmentId"))); - - PaginationContext context = new PaginationContext<>(10); - PaginationResponse page1 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, context); - PaginationResponse page2 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page1.getContext()); - PaginationResponse page3 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page2.getContext()); - PaginationResponse page4 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page3.getContext()); - PaginationResponse page5 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page4.getContext()); - PaginationResponse page6 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page5.getContext()); - PaginationResponse page7 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page6.getContext()); - - //verify returned pages - assertEquals(10, page1.getItems().size()); - assertEquals(10, page2.getItems().size()); - assertEquals(10, page3.getItems().size()); - assertEquals(10, page4.getItems().size()); - assertEquals(10, page5.getItems().size()); - - page1.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page2.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page3.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page4.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - page5.getItems().forEach(e -> assertEquals(customerId_1, e.getCustomerId()) ); - - assertEquals(0, page6.getItems().size()); - assertEquals(0, page7.getItems().size()); - - assertFalse(page1.getContext().isLastPage()); - assertFalse(page2.getContext().isLastPage()); - assertFalse(page3.getContext().isLastPage()); - assertFalse(page4.getContext().isLastPage()); - assertFalse(page5.getContext().isLastPage()); - - assertTrue(page6.getContext().isLastPage()); - assertTrue(page7.getContext().isLastPage()); - - List expectedPage3Strings = new ArrayList<>(Arrays.asList(new String[]{"qr_20", "qr_21", "qr_22", "qr_23", "qr_24", "qr_25", "qr_26", "qr_27", "qr_28", "qr_29" })); - List actualPage3Strings = new ArrayList<>(); - page3.getItems().stream().forEach( ce -> actualPage3Strings.add(((TestSystemEvent) ce.getDetails()).getPayload()) ); - - assertEquals(expectedPage3Strings, actualPage3Strings); - - //test first page of the results with empty sort order -> default sort order (by createdTimestamp ascending) - PaginationResponse page1EmptySort = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, Collections.emptyList(), context); - assertEquals(10, page1EmptySort.getItems().size()); - - List expectedPage1EmptySortStrings = new ArrayList<>(Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" })); - List actualPage1EmptySortStrings = new ArrayList<>(); - page1EmptySort.getItems().stream().forEach( ce -> actualPage1EmptySortStrings.add(((TestSystemEvent) ce.getDetails()).getPayload()) ); - - assertEquals(expectedPage1EmptySortStrings, actualPage1EmptySortStrings); - - //test first page of the results with null sort order -> default sort order (by createdTimestamp ascending) - PaginationResponse page1NullSort = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, null, context); - assertEquals(10, page1NullSort.getItems().size()); - - List expectedPage1NullSortStrings = new ArrayList<>(Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" })); - List actualPage1NullSortStrings = new ArrayList<>(); - page1NullSort.getItems().stream().forEach( ce -> actualPage1NullSortStrings.add(((TestSystemEvent) ce.getDetails()).getPayload()) ); - - assertEquals(expectedPage1NullSortStrings, actualPage1NullSortStrings); - - - //test first page of the results with sort descending order by a equipmentId property - cassandra ignores specified sort order - PaginationResponse page1SingleSortDesc = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, Collections.singletonList(new ColumnAndSort("equipmentId", SortOrder.desc)), context); - assertEquals(10, page1SingleSortDesc.getItems().size()); - - List expectedPage1SingleSortDescStrings = new ArrayList< >(Arrays.asList(new String[]{"qr_0", "qr_1", "qr_2", "qr_3", "qr_4", "qr_5", "qr_6", "qr_7", "qr_8", "qr_9" })); - List actualPage1SingleSortDescStrings = new ArrayList<>(); - page1SingleSortDesc.getItems().stream().forEach( ce -> actualPage1SingleSortDescStrings.add(((TestSystemEvent) ce.getDetails()).getPayload()) ); - - assertEquals(expectedPage1SingleSortDescStrings, actualPage1SingleSortDescStrings); - - //testInterface.delete(System.currentTimeMillis()); - - used_equipmentIds.forEach(eqId -> testInterface.delete(customerId_1, eqId, System.currentTimeMillis())); - used_equipmentIds.forEach(eqId -> testInterface.delete(customerId_2, eqId, System.currentTimeMillis())); - - } } diff --git a/system-event-datastore-common-test/src/main/java/com/telecominfraproject/wlan/systemevent/datastore/BaseSystemEventDatastoreTest.java b/system-event-datastore-common-test/src/main/java/com/telecominfraproject/wlan/systemevent/datastore/BaseSystemEventDatastoreTest.java index f239f04e..c43f8176 100644 --- a/system-event-datastore-common-test/src/main/java/com/telecominfraproject/wlan/systemevent/datastore/BaseSystemEventDatastoreTest.java +++ b/system-event-datastore-common-test/src/main/java/com/telecominfraproject/wlan/systemevent/datastore/BaseSystemEventDatastoreTest.java @@ -34,7 +34,7 @@ public abstract class BaseSystemEventDatastoreTest { protected SystemEventDatastore testInterface; protected static final AtomicLong testSequence = new AtomicLong(1); - + @Test public void testCRD() { long baseTimestamp = System.currentTimeMillis(); @@ -216,7 +216,7 @@ public abstract class BaseSystemEventDatastoreTest { PaginationResponse page1SingleSortDesc = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, Collections.singletonList(new ColumnAndSort("equipmentId", SortOrder.desc)), context); assertEquals(10, page1SingleSortDesc.getItems().size()); - List expectedPage1SingleSortDescStrings = new ArrayList< >(Arrays.asList(new String[]{"qr_49", "qr_48", "qr_47", "qr_46", "qr_45", "qr_44", "qr_43", "qr_42", "qr_41", "qr_40" })); + List expectedPage1SingleSortDescStrings = getPagination_expectedPage1SingleSortDescStrings(); List actualPage1SingleSortDescStrings = new ArrayList<>(); page1SingleSortDesc.getItems().stream().forEach( ce -> actualPage1SingleSortDescStrings.add(((TestSystemEvent) ce.getDetails()).getPayload()) ); @@ -228,6 +228,10 @@ public abstract class BaseSystemEventDatastoreTest { used_equipmentIds.forEach(eqId -> testInterface.delete(customerId_2, eqId, System.currentTimeMillis())); } + + protected List getPagination_expectedPage1SingleSortDescStrings(){ + return Arrays.asList(new String[]{"qr_49", "qr_48", "qr_47", "qr_46", "qr_45", "qr_44", "qr_43", "qr_42", "qr_41", "qr_40" }); + } @Test