in Cassandra data stores rely only on nextPagingState to set the lastPage indicator

This commit is contained in:
Dmitry Toptygin
2021-01-12 18:09:47 -05:00
parent c0338474b0
commit da9db6df2c
20 changed files with 307 additions and 1237 deletions

View File

@@ -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;
}

View File

@@ -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<Long> equipmentIds = new HashSet<>();
Set<AlarmCode> alarmCodes = new HashSet<>(Arrays.asList(AlarmCode.AccessPointIsUnreachable, AlarmCode.AssocFailure));
long pastTimestamp = 0;
Set<Long> 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<ColumnAndSort> 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<Alarm> context = new PaginationContext<>(10);
PaginationResponse<Alarm> page1 = null;
PaginationResponse<Alarm> page2 = null;
PaginationResponse<Alarm> page3 = null;
PaginationResponse<Alarm> page4 = null;
PaginationResponse<Alarm> page5 = null;
PaginationResponse<Alarm> page6 = null;
PaginationResponse<Alarm> 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<String> 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<String> actualPage3Strings = new ArrayList<>();
page3.getItems().stream().forEach( ce -> actualPage3Strings.add(ce.getScopeId()) );
assertEquals(expectedPage3Strings, actualPage3Strings);
List<String> 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<Alarm> page1EmptySort = testInterface.getForCustomer(customerId_1, null, null, -1, Collections.emptyList(), context);
assertEquals(10, page1EmptySort.getItems().size());
List<String> expectedPage1EmptySortStrings = new ArrayList<>(expectedPage1Strings);
List<String> 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<Alarm> page1NullSort = testInterface.getForCustomer(customerId_1, null, null, -1, null, context);
assertEquals(10, page1NullSort.getItems().size());
List<String> expectedPage1NullSortStrings = new ArrayList<>(expectedPage1Strings);
List<String> 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<Alarm> page1SingleSortDesc = testInterface.getForCustomer(customerId_1, null, null, -1, Collections.singletonList(new ColumnAndSort("equipmentId", SortOrder.desc)), context);
assertEquals(10, page1SingleSortDesc.getItems().size());
List<String> expectedPage1SingleSortDescStrings = new ArrayList<>(expectedPage1Strings);
List<String> 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<String> 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<String> 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<String> getAlarmPagination_expectedPage1SingleSortDescStrings(){
return getAlarmPagination_expectedPage1EmptySortStrings();
}
}

View File

@@ -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<Long> equipmentIds = new HashSet<>();
Set<AlarmCode> alarmCodes = new HashSet<>(Arrays.asList(AlarmCode.AccessPointIsUnreachable, AlarmCode.AssocFailure));
long pastTimestamp = 0;
Set<Long> 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<String> 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<String> expectedPage3Strings = getAlarmPagination_expectedPage3Strings();
List<String> actualPage3Strings = new ArrayList<>();
page3.getItems().stream().forEach( ce -> actualPage3Strings.add(ce.getScopeId()) );
@@ -285,7 +290,7 @@ public abstract class BaseAlarmDatastoreTest {
PaginationResponse<Alarm> page1EmptySort = testInterface.getForCustomer(customerId_1, null, null, -1, Collections.emptyList(), context);
assertEquals(10, page1EmptySort.getItems().size());
List<String> 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<String> expectedPage1EmptySortStrings = getAlarmPagination_expectedPage1EmptySortStrings();
List<String> actualPage1EmptySortStrings = new ArrayList<>();
page1EmptySort.getItems().stream().forEach( ce -> actualPage1EmptySortStrings.add(ce.getScopeId()) );
@@ -295,7 +300,7 @@ public abstract class BaseAlarmDatastoreTest {
PaginationResponse<Alarm> page1NullSort = testInterface.getForCustomer(customerId_1, null, null, -1, null, context);
assertEquals(10, page1NullSort.getItems().size());
List<String> 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<String> expectedPage1NullSortStrings = expectedPage1EmptySortStrings;
List<String> actualPage1NullSortStrings = new ArrayList<>();
page1NullSort.getItems().stream().forEach( ce -> actualPage1NullSortStrings.add(ce.getScopeId()) );
@@ -306,7 +311,7 @@ public abstract class BaseAlarmDatastoreTest {
PaginationResponse<Alarm> page1SingleSortDesc = testInterface.getForCustomer(customerId_1, null, null, -1, Collections.singletonList(new ColumnAndSort("equipmentId", SortOrder.desc)), context);
assertEquals(10, page1SingleSortDesc.getItems().size());
List<String> 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<String> expectedPage1SingleSortDescStrings = getAlarmPagination_expectedPage1SingleSortDescStrings();
List<String> 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<String> 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<String> 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<String> 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();

View File

@@ -440,7 +440,7 @@ public class ClientDAO {
ArrayList<Object> 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;
}

View File

@@ -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;
}
}

View File

@@ -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<Client> 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<String> 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<String> 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<ColumnAndSort> sortBy = new ArrayList<>();
//Cassandra has limited support for sorting. Not going to sort the results
//sortBy.addAll(Arrays.asList(new ColumnAndSort("macAddress")));
PaginationContext<Client> context = new PaginationContext<>(10);
PaginationResponse<Client> page1 = testInterface.getForCustomer(customerId_1, sortBy, context);
PaginationResponse<Client> page2 = testInterface.getForCustomer(customerId_1, sortBy, page1.getContext());
PaginationResponse<Client> page3 = testInterface.getForCustomer(customerId_1, sortBy, page2.getContext());
PaginationResponse<Client> page4 = testInterface.getForCustomer(customerId_1, sortBy, page3.getContext());
PaginationResponse<Client> page5 = testInterface.getForCustomer(customerId_1, sortBy, page4.getContext());
PaginationResponse<Client> page6 = testInterface.getForCustomer(customerId_1, sortBy, page5.getContext());
PaginationResponse<Client> 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<String> 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<String> 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<Client> page1EmptySort = testInterface.getForCustomer(customerId_1, Collections.emptyList(), context);
assertEquals(10, page1EmptySort.getItems().size());
List<String> 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<String> actualPage1EmptySortStrings = new ArrayList<>();
page1EmptySort.getItems().stream().forEach( ce -> actualPage1EmptySortStrings.add(((ClientInfoDetails)ce.getDetails()).getAlias()) );
assertEquals(expectedPage1EmptySortStrings, actualPage1EmptySortStrings);
@Override
protected List<String> 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<Client> page1NullSort = testInterface.getForCustomer(customerId_1, null, context);
assertEquals(10, page1NullSort.getItems().size());
List<String> expectedPage1NullSortStrings = new ArrayList<>(expectedPage1EmptySortStrings);
List<String> 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<Client> page1SingleSortDesc = testInterface.getForCustomer(customerId_1, Collections.singletonList(new ColumnAndSort("macAddress", SortOrder.desc)), context);
assertEquals(10, page1SingleSortDesc.getItems().size());
List<String> expectedPage1SingleSortDescStrings = new ArrayList<>(expectedPage1EmptySortStrings);
List<String> 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<String> 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<ClientSession> 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<ClientSession> createdList = testInterface.updateSessions(sessionsToCreate);
List<ClientSessionDetails> createdDetailsList = new ArrayList<>();
List<ClientSessionDetails> detailsToCreateList = new ArrayList<>();
sessionsToCreate.forEach(s -> detailsToCreateList.add(s.getDetails()));
createdList.forEach(s -> createdDetailsList.add(s.getDetails()));
assertEquals(detailsToCreateList, createdDetailsList);
List<ClientSession> 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<ColumnAndSort> sortBy = new ArrayList<>();
//Cassandra has limited support for sorting, we're not using that feature
//sortBy.addAll(Arrays.asList(new ColumnAndSort("macAddress")));
PaginationContext<ClientSession> context = new PaginationContext<>(10);
PaginationResponse<ClientSession> page1 = testInterface.getSessionsForCustomer(customerId_1, null, null, sortBy, context);
PaginationResponse<ClientSession> page2 = testInterface.getSessionsForCustomer(customerId_1, null, null, sortBy, page1.getContext());
PaginationResponse<ClientSession> page3 = testInterface.getSessionsForCustomer(customerId_1, null, null, sortBy, page2.getContext());
PaginationResponse<ClientSession> page4 = testInterface.getSessionsForCustomer(customerId_1, null, null, sortBy, page3.getContext());
PaginationResponse<ClientSession> page5 = testInterface.getSessionsForCustomer(customerId_1, null, null, sortBy, page4.getContext());
PaginationResponse<ClientSession> page6 = testInterface.getSessionsForCustomer(customerId_1, null, null, sortBy, page5.getContext());
PaginationResponse<ClientSession> 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<String> expectedAllPagesStrings = new HashSet<>();
for(int i=0; i<50; i++) {
expectedAllPagesStrings.add("qr_"+i);
}
Set<String> 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<ClientSession> context100 = new PaginationContext<>(100);
//test first page of the results with empty sort order -> sort order is weird but consistent
PaginationResponse<ClientSession> page1EmptySort = testInterface.getSessionsForCustomer(customerId_1, null, null, Collections.emptyList(), context100);
assertEquals(50, page1EmptySort.getItems().size());
Set<String> expectedPage1EmptySortStrings = new HashSet<>(expectedAllPagesStrings);
Set<String> 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<ClientSession> page1NullSort = testInterface.getSessionsForCustomer(customerId_1, null, null, null, context100);
assertEquals(50, page1NullSort.getItems().size());
Set<String> expectedPage1NullSortStrings = new HashSet<>(expectedPage1EmptySortStrings);
Set<String> 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<ClientSession> page1SingleSortDesc = testInterface.getSessionsForCustomer(customerId_1, null, null, Collections.singletonList(new ColumnAndSort("macAddress", SortOrder.desc)), context100);
assertEquals(50, page1SingleSortDesc.getItems().size());
Set<String> expectedPage1SingleSortDescStrings = new HashSet<>(expectedPage1EmptySortStrings);
Set<String> 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<ClientSession> page1Eq_1 = testInterface.getSessionsForCustomer(customerId_1, new HashSet<Long>(Arrays.asList(equipmentId_1)), null, Collections.emptyList(), context);
PaginationResponse<ClientSession> page2Eq_1 = testInterface.getSessionsForCustomer(customerId_1, new HashSet<Long>(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<String> 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<String> 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<ClientSession> page1Eq_2 = testInterface.getSessionsForCustomer(customerId_1, new HashSet<Long>(Arrays.asList(equipmentId_2)), null, Collections.emptyList(), context);
PaginationResponse<ClientSession> page2Eq_2 = testInterface.getSessionsForCustomer(customerId_1, new HashSet<Long>(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<String> 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<String> 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<ClientSession> page1Eq_1or2 = testInterface.getSessionsForCustomer(customerId_1, new HashSet<Long>(Arrays.asList(equipmentId_1, equipmentId_2)), null, Collections.emptyList(), context);
PaginationResponse<ClientSession> page2Eq_1or2 = testInterface.getSessionsForCustomer(customerId_1, new HashSet<Long>(Arrays.asList(equipmentId_1, equipmentId_2)), null, Collections.emptyList(), page1Eq_1or2.getContext());
PaginationResponse<ClientSession> page3Eq_1or2 = testInterface.getSessionsForCustomer(customerId_1, new HashSet<Long>(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<String> 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<String> actualPage1Eq_1or2Strings = new ArrayList<>();
page1Eq_1or2.getItems().stream().forEach( ce -> actualPage1Eq_1or2Strings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) );
assertEquals(expectedPage1Eq_1or2Strings, actualPage1Eq_1or2Strings);
List<String> 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<String> 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<Long>(Arrays.asList(locationId_1)), Collections.emptyList(), context);
page2Eq_1 = testInterface.getSessionsForCustomer(customerId_1, null, new HashSet<Long>(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<String> 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<Long>(Arrays.asList(locationId_2)), Collections.emptyList(), context);
page2Eq_2 = testInterface.getSessionsForCustomer(customerId_1, null, new HashSet<Long>(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<String> 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<Long>(Arrays.asList(locationId_1, locationId_2)), Collections.emptyList(), context);
page2Eq_1or2 = testInterface.getSessionsForCustomer(customerId_1, null, new HashSet<Long>(Arrays.asList(locationId_1, locationId_2)), Collections.emptyList(), page1Eq_1or2.getContext());
page3Eq_1or2 = testInterface.getSessionsForCustomer(customerId_1, null, new HashSet<Long>(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<String> 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<String> 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<Long>(Arrays.asList(equipmentId_1)), new HashSet<Long>(Arrays.asList(locationId_1, locationId_2)), Collections.emptyList(), context);
page2Eq_1 = testInterface.getSessionsForCustomer(customerId_1, new HashSet<Long>(Arrays.asList(equipmentId_1)), new HashSet<Long>(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<String> 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<String> 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<String> 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<String> getClientSessionPagination_expectedPage1SingleSortDescStrings() {
return getClientSessionPagination_expectedPage1EmptySortStrings();
}
}

View File

@@ -264,7 +264,7 @@ public abstract class BaseClientDatastoreTest {
PaginationResponse<Client> page1SingleSortDesc = testInterface.searchByMacAddress(customerId_1, "A1", Collections.singletonList(new ColumnAndSort("macAddress", SortOrder.desc)), context);
assertEquals(10, page1SingleSortDesc.getItems().size());
List<String> 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<String> expectedPage1SingleSortDescStrings = getSearchByMac_ExpectedPage1SingleSortDescStrings();
List<String> 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<String> 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<String> 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<String> expectedPage3Strings = getClientPagination_ExpectedPage3Strings();
List<String> actualPage3Strings = new ArrayList<>();
page3.getItems().stream().forEach( ce -> actualPage3Strings.add(((ClientInfoDetails)ce.getDetails()).getAlias()) );
@@ -447,7 +454,7 @@ public abstract class BaseClientDatastoreTest {
PaginationResponse<Client> page1EmptySort = testInterface.getForCustomer(customerId_1, Collections.emptyList(), context);
assertEquals(10, page1EmptySort.getItems().size());
List<String> 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<String> expectedPage1EmptySortStrings = getClientPagination_ExpectedPage1EmptySortStrings();
List<String> actualPage1EmptySortStrings = new ArrayList<>();
page1EmptySort.getItems().stream().forEach( ce -> actualPage1EmptySortStrings.add(((ClientInfoDetails)ce.getDetails()).getAlias()) );
@@ -457,7 +464,7 @@ public abstract class BaseClientDatastoreTest {
PaginationResponse<Client> page1NullSort = testInterface.getForCustomer(customerId_1, null, context);
assertEquals(10, page1NullSort.getItems().size());
List<String> 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<String> expectedPage1NullSortStrings = new ArrayList<>(expectedPage1EmptySortStrings);
List<String> actualPage1NullSortStrings = new ArrayList<>();
page1NullSort.getItems().stream().forEach( ce -> actualPage1NullSortStrings.add(((ClientInfoDetails)ce.getDetails()).getAlias()) );
@@ -468,7 +475,7 @@ public abstract class BaseClientDatastoreTest {
PaginationResponse<Client> page1SingleSortDesc = testInterface.getForCustomer(customerId_1, Collections.singletonList(new ColumnAndSort("macAddress", SortOrder.desc)), context);
assertEquals(10, page1SingleSortDesc.getItems().size());
List<String> 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<String> expectedPage1SingleSortDescStrings = getClientPagination_ExpectedPage1SingleSortDescStrings();
List<String> actualPage1SingleSortDescStrings = new ArrayList<>();
page1SingleSortDesc.getItems().stream().forEach( ce -> actualPage1SingleSortDescStrings.add(((ClientInfoDetails)ce.getDetails()).getAlias()) );
@@ -478,6 +485,18 @@ public abstract class BaseClientDatastoreTest {
}
protected List<String> 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<String> 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<String> 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<String> expectedAllPagesStrings = new HashSet<>();
for(int i=0; i<50; i++) {
expectedAllPagesStrings.add("qr_"+i);
}
Set<String> actualAllPagesStrings = new HashSet<>();
List<String> 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<String> expectedPage3Strings = getClientSessionPagination_expectedPage3Strings();
List<String> actualPage3Strings = new ArrayList<>();
page3.getItems().stream().forEach( ce -> actualPage3Strings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) );
@@ -861,7 +894,7 @@ public abstract class BaseClientDatastoreTest {
PaginationResponse<ClientSession> page1EmptySort = testInterface.getSessionsForCustomer(customerId_1, null, null, Collections.emptyList(), context);
assertEquals(10, page1EmptySort.getItems().size());
List<String> 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<String> expectedPage1EmptySortStrings = getClientSessionPagination_expectedPage1EmptySortStrings();
List<String> actualPage1EmptySortStrings = new ArrayList<>();
page1EmptySort.getItems().stream().forEach( ce -> actualPage1EmptySortStrings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) );
@@ -871,7 +904,7 @@ public abstract class BaseClientDatastoreTest {
PaginationResponse<ClientSession> page1NullSort = testInterface.getSessionsForCustomer(customerId_1, null, null, null, context);
assertEquals(10, page1NullSort.getItems().size());
List<String> 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<String> expectedPage1NullSortStrings = getClientSessionPagination_expectedPage1EmptySortStrings();
List<String> actualPage1NullSortStrings = new ArrayList<>();
page1NullSort.getItems().stream().forEach( ce -> actualPage1NullSortStrings.add(((ClientSessionDetails)ce.getDetails()).getApFingerprint()) );
@@ -882,7 +915,7 @@ public abstract class BaseClientDatastoreTest {
PaginationResponse<ClientSession> page1SingleSortDesc = testInterface.getSessionsForCustomer(customerId_1, null, null, Collections.singletonList(new ColumnAndSort("macAddress", SortOrder.desc)), context);
assertEquals(10, page1SingleSortDesc.getItems().size());
List<String> 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<String> expectedPage1SingleSortDescStrings = getClientSessionPagination_expectedPage1SingleSortDescStrings();
List<String> 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<String> 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<String> 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<String> 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();

View File

@@ -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;
}

View File

@@ -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<EquipmentRoutingRecord> 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<ColumnAndSort> sortBy = new ArrayList<>();
//Note: sort order is ignored by cassandra
//sortBy.addAll(Arrays.asList(new ColumnAndSort("equipmentId")));
PaginationContext<EquipmentRoutingRecord> context = new PaginationContext<>(10);
PaginationResponse<EquipmentRoutingRecord> page1 = testInterface.getForCustomer(customerId_1, sortBy, context);
PaginationResponse<EquipmentRoutingRecord> page2 = testInterface.getForCustomer(customerId_1, sortBy, page1.getContext());
PaginationResponse<EquipmentRoutingRecord> page3 = testInterface.getForCustomer(customerId_1, sortBy, page2.getContext());
PaginationResponse<EquipmentRoutingRecord> page4 = testInterface.getForCustomer(customerId_1, sortBy, page3.getContext());
PaginationResponse<EquipmentRoutingRecord> page5 = testInterface.getForCustomer(customerId_1, sortBy, page4.getContext());
PaginationResponse<EquipmentRoutingRecord> page6 = testInterface.getForCustomer(customerId_1, sortBy, page5.getContext());
PaginationResponse<EquipmentRoutingRecord> 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<EquipmentRoutingRecord> page1EmptySort = testInterface.getForCustomer(customerId_1, Collections.emptyList(), context);
assertEquals(10, page1EmptySort.getItems().size());
List<Long> 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<EquipmentRoutingRecord> page1NullSort = testInterface.getForCustomer(customerId_1, null, context);
assertEquals(10, page1NullSort.getItems().size());
List<Long> expectedPage1NullSortLongs = new ArrayList<>(actualPage1EmptySortLongs);
List<Long> 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<EquipmentRoutingRecord> page1SingleSortDesc = testInterface.getForCustomer(customerId_1, Collections.singletonList(new ColumnAndSort("equipmentId", SortOrder.desc)), context);
assertEquals(10, page1SingleSortDesc.getItems().size());
List<Long> expectedPage1SingleSortDescLongs = new ArrayList<>(actualPage1EmptySortLongs);
List<Long> 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<Long> getRoutingPagination_expectedPage1SingleSortDescLongs(int customerId){
return getRoutingPagination_expectedPage1EmptySortLongs(customerId);
}
@Override
protected List<Long> getRoutingPagination_expectedPage1EmptySortLongs(int customerId){
List<Long> actualPage1EmptySortLongs = new ArrayList<>();
testInterface
.getForCustomer(customerId, Collections.emptyList(), new PaginationContext<EquipmentRoutingRecord>(10))
.getItems().forEach(ce -> actualPage1EmptySortLongs.add(ce.getEquipmentId()));
return actualPage1EmptySortLongs;
}
@Override
protected List<Long> getRoutingPagination_expectedPage3Longs(){
return Collections.emptyList();
}
}

View File

@@ -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;

View File

@@ -260,18 +260,21 @@ public abstract class BaseRoutingDatastoreTest {
assertTrue(page6.getContext().isLastPage());
assertTrue(page7.getContext().isLastPage());
List<Long> expectedPage3Longs = new ArrayList< >(Arrays.asList(new Long[]{20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L }));
List<Long> expectedPage3Longs = getRoutingPagination_expectedPage3Longs();
List<Long> 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<EquipmentRoutingRecord> page1EmptySort = testInterface.getForCustomer(customerId_1, Collections.emptyList(), context);
assertEquals(10, page1EmptySort.getItems().size());
List<Long> expectedPage1EmptySortLongs = new ArrayList<>(Arrays.asList(new Long[]{0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L }));
List<Long> expectedPage1EmptySortLongs = getRoutingPagination_expectedPage1EmptySortLongs(customerId_1);
List<Long> actualPage1EmptySortLongs = new ArrayList<>();
page1EmptySort.getItems().stream().forEach( ce -> actualPage1EmptySortLongs.add( ce.getEquipmentId()) );
@@ -281,7 +284,7 @@ public abstract class BaseRoutingDatastoreTest {
PaginationResponse<EquipmentRoutingRecord> page1NullSort = testInterface.getForCustomer(customerId_1, null, context);
assertEquals(10, page1NullSort.getItems().size());
List<Long> expectedPage1NullSortLongs = new ArrayList<>(Arrays.asList(new Long[]{0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L }));
List<Long> expectedPage1NullSortLongs = expectedPage1EmptySortLongs;
List<Long> actualPage1NullSortLongs = new ArrayList<>();
page1NullSort.getItems().stream().forEach( ce -> actualPage1NullSortLongs.add( ce.getEquipmentId()) );
@@ -292,7 +295,7 @@ public abstract class BaseRoutingDatastoreTest {
PaginationResponse<EquipmentRoutingRecord> page1SingleSortDesc = testInterface.getForCustomer(customerId_1, Collections.singletonList(new ColumnAndSort("equipmentId", SortOrder.desc)), context);
assertEquals(10, page1SingleSortDesc.getItems().size());
List<Long> expectedPage1SingleSortDescLongs = new ArrayList< >(Arrays.asList(new Long[]{ 49L, 48L, 47L, 46L, 45L, 44L, 43L, 42L, 41L, 40L }));
List<Long> expectedPage1SingleSortDescLongs = getRoutingPagination_expectedPage1SingleSortDescLongs(customerId_1);
List<Long> actualPage1SingleSortDescLongs = new ArrayList<>();
page1SingleSortDesc.getItems().stream().forEach( ce -> actualPage1SingleSortDescLongs.add( ce.getEquipmentId()) );
@@ -303,6 +306,19 @@ public abstract class BaseRoutingDatastoreTest {
}
protected List<Long> getRoutingPagination_expectedPage1SingleSortDescLongs(int customerId){
return Arrays.asList(new Long[]{ 49L, 48L, 47L, 46L, 45L, 44L, 43L, 42L, 41L, 40L });
}
protected List<Long> getRoutingPagination_expectedPage1EmptySortLongs(int customerId){
return Arrays.asList(new Long[]{0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L });
}
protected List<Long> 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();

View File

@@ -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

View File

@@ -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<String> 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<Long> 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<ColumnAndSort> sortBy = new ArrayList<>();
sortBy.addAll(Arrays.asList(new ColumnAndSort("equipmentId")));
PaginationContext<ServiceMetric> context = new PaginationContext<>(10);
PaginationResponse<ServiceMetric> page1 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, context);
PaginationResponse<ServiceMetric> page2 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page1.getContext());
PaginationResponse<ServiceMetric> page3 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page2.getContext());
PaginationResponse<ServiceMetric> page4 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page3.getContext());
PaginationResponse<ServiceMetric> page5 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page4.getContext());
PaginationResponse<ServiceMetric> page6 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page5.getContext());
PaginationResponse<ServiceMetric> 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<String> 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<String> 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<ServiceMetric> page1EmptySort = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, Collections.emptyList(), context);
assertEquals(10, page1EmptySort.getItems().size());
List<String> 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<String> 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<ServiceMetric> page1NullSort = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, null, context);
assertEquals(10, page1NullSort.getItems().size());
List<String> 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<String> 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<ServiceMetric> 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<String> 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<String> 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()));
}
}

View File

@@ -231,7 +231,7 @@ public abstract class BaseServiceMetricDatastoreTest {
PaginationResponse<ServiceMetric> 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<String> 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<String> expectedPage1SingleSortDescStrings = getPagination_expectedPage1SingleSortDescStrings();
List<String> actualPage1SingleSortDescStrings = new ArrayList<>();
page1SingleSortDesc.getItems().stream().forEach( ce -> actualPage1SingleSortDescStrings.add(((ClientMetrics) ce.getDetails()).getClassificationName() ) );
@@ -242,6 +242,9 @@ public abstract class BaseServiceMetricDatastoreTest {
}
protected List<String> 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() {

View File

@@ -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;
}

View File

@@ -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<Status> 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<ColumnAndSort> sortBy = new ArrayList<>();
//NOTE: sort order is ignored by the Cassandra DAO
sortBy.addAll(Arrays.asList(new ColumnAndSort("equipmentId")));
PaginationContext<Status> context = new PaginationContext<>(10);
PaginationResponse<Status> page1 = testInterface.getForCustomer(customerId_1, sortBy, context);
PaginationResponse<Status> page2 = testInterface.getForCustomer(customerId_1, sortBy, page1.getContext());
PaginationResponse<Status> page3 = testInterface.getForCustomer(customerId_1, sortBy, page2.getContext());
PaginationResponse<Status> page4 = testInterface.getForCustomer(customerId_1, sortBy, page3.getContext());
PaginationResponse<Status> page5 = testInterface.getForCustomer(customerId_1, sortBy, page4.getContext());
PaginationResponse<Status> page6 = testInterface.getForCustomer(customerId_1, sortBy, page5.getContext());
PaginationResponse<Status> 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<String> 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<String> 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<Status> 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<String> 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<String> 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<Status> 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<String> 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<String> 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<Status> 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<String> 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<String> 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<String> getStatusPagination_expectedPage1SingleSortDescStrings(){
return getStatusPagination_expectedPage1EmptySortStrings();
}
@Override
protected List<String> 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<String> 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" });
}
}

View File

@@ -236,7 +236,7 @@ public abstract class BaseStatusDatastoreTest {
assertTrue(page6.getContext().isLastPage());
assertTrue(page7.getContext().isLastPage());
List<String> 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<String> expectedPage3Strings = getStatusPagination_expectedPage3Strings();
List<String> actualPage3Strings = new ArrayList<>();
page3.getItems().stream().forEach( ce -> actualPage3Strings.add(((EquipmentAdminStatusData) ce.getDetails()).getStatusMessage()) );
@@ -254,7 +254,7 @@ public abstract class BaseStatusDatastoreTest {
PaginationResponse<Status> page1EmptySort = testInterface.getForCustomer(customerId_1, Collections.emptyList(), context);
assertEquals(10, page1EmptySort.getItems().size());
List<String> 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<String> expectedPage1EmptySortStrings = getStatusPagination_expectedPage1EmptySortStrings();
List<String> actualPage1EmptySortStrings = new ArrayList<>();
page1EmptySort.getItems().stream().forEach( ce -> actualPage1EmptySortStrings.add(((EquipmentAdminStatusData) ce.getDetails()).getStatusMessage()) );
@@ -264,7 +264,7 @@ public abstract class BaseStatusDatastoreTest {
PaginationResponse<Status> page1NullSort = testInterface.getForCustomer(customerId_1, null, context);
assertEquals(10, page1NullSort.getItems().size());
List<String> 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<String> expectedPage1NullSortStrings = expectedPage1EmptySortStrings;
List<String> actualPage1NullSortStrings = new ArrayList<>();
page1NullSort.getItems().stream().forEach( ce -> actualPage1NullSortStrings.add(((EquipmentAdminStatusData) ce.getDetails()).getStatusMessage()) );
@@ -275,7 +275,7 @@ public abstract class BaseStatusDatastoreTest {
PaginationResponse<Status> page1SingleSortDesc = testInterface.getForCustomer(customerId_1, Collections.singletonList(new ColumnAndSort("equipmentId", SortOrder.desc)), context);
assertEquals(10, page1SingleSortDesc.getItems().size());
List<String> 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<String> expectedPage1SingleSortDescStrings = getStatusPagination_expectedPage1SingleSortDescStrings();
List<String> actualPage1SingleSortDescStrings = new ArrayList<>();
page1SingleSortDesc.getItems().stream().forEach( ce -> actualPage1SingleSortDescStrings.add(((EquipmentAdminStatusData) ce.getDetails()).getStatusMessage()) );
@@ -286,6 +286,18 @@ public abstract class BaseStatusDatastoreTest {
}
protected List<String> 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<String> 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<String> 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);

View File

@@ -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

View File

@@ -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<String> 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<Long> 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<ColumnAndSort> sortBy = new ArrayList<>();
sortBy.addAll(Arrays.asList(new ColumnAndSort("equipmentId")));
PaginationContext<SystemEventRecord> context = new PaginationContext<>(10);
PaginationResponse<SystemEventRecord> page1 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, context);
PaginationResponse<SystemEventRecord> page2 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page1.getContext());
PaginationResponse<SystemEventRecord> page3 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page2.getContext());
PaginationResponse<SystemEventRecord> page4 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page3.getContext());
PaginationResponse<SystemEventRecord> page5 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page4.getContext());
PaginationResponse<SystemEventRecord> page6 = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, sortBy, page5.getContext());
PaginationResponse<SystemEventRecord> 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<String> 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<String> 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<SystemEventRecord> page1EmptySort = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, Collections.emptyList(), context);
assertEquals(10, page1EmptySort.getItems().size());
List<String> 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<String> 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<SystemEventRecord> page1NullSort = testInterface.getForCustomer(fromTime, toTime, customerId_1, null, null, null, null, null, context);
assertEquals(10, page1NullSort.getItems().size());
List<String> 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<String> 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<SystemEventRecord> 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<String> 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<String> 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()));
}
}

View File

@@ -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<SystemEventRecord> 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<String> 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<String> expectedPage1SingleSortDescStrings = getPagination_expectedPage1SingleSortDescStrings();
List<String> 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<String> 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