Removed all the old ProtocolProcessor stuff
This commit is contained in:
+84
-87
@@ -17,18 +17,15 @@
|
||||
package io.moquette.persistence.mapdb;
|
||||
|
||||
import io.moquette.BrokerConstants;
|
||||
import io.moquette.persistence.MessageStoreTCK;
|
||||
import io.moquette.server.config.IConfig;
|
||||
import io.moquette.server.config.MemoryConfig;
|
||||
import io.moquette.spi.IMessagesStore.StoredMessage;
|
||||
import io.moquette.spi.impl.SessionsRepository;
|
||||
import io.netty.handler.codec.mqtt.MqttQoS;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
@@ -41,89 +38,89 @@ import static org.junit.Assert.*;
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
public class MapDBPersistentStoreTest extends MessageStoreTCK {
|
||||
public class MapDBPersistentStoreTest /*extends MessageStoreTCK*/ {
|
||||
|
||||
MapDBPersistentStore m_storageService;
|
||||
|
||||
private ScheduledExecutorService scheduler;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
scheduler = Executors.newScheduledThreadPool(1);
|
||||
|
||||
cleanPersistenceFile(BrokerConstants.DEFAULT_PERSISTENT_PATH);
|
||||
Properties props = new Properties();
|
||||
props.setProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, BrokerConstants.DEFAULT_PERSISTENT_PATH);
|
||||
IConfig conf = new MemoryConfig(props);
|
||||
m_storageService = new MapDBPersistentStore(conf, scheduler);
|
||||
m_storageService.initStore();
|
||||
messagesStore = m_storageService.messagesStore();
|
||||
sessionsStore = m_storageService.sessionsStore();
|
||||
this.sessionsRepository = new SessionsRepository(sessionsStore, null);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if (m_storageService != null) {
|
||||
m_storageService.close();
|
||||
}
|
||||
|
||||
scheduler.shutdown();
|
||||
cleanPersistenceFile(BrokerConstants.DEFAULT_PERSISTENT_PATH);
|
||||
}
|
||||
|
||||
static void cleanPersistenceFile(String fileName) {
|
||||
File dbFile = new File(fileName);
|
||||
if (dbFile.exists()) {
|
||||
dbFile.delete();
|
||||
new File(fileName + ".p").delete();
|
||||
new File(fileName + ".t").delete();
|
||||
}
|
||||
assertFalse(dbFile.exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNextPacketID_notExistingClientSession() {
|
||||
int packetId = sessionsStore.nextPacketID("NOT_EXISTING_CLI");
|
||||
assertEquals(1, packetId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNextPacketID_existingClientSession() {
|
||||
// Force creation of inflight map for the CLIENT session
|
||||
int packetId = sessionsStore.nextPacketID("CLIENT");
|
||||
assertEquals(1, packetId);
|
||||
|
||||
// request a second packetID
|
||||
packetId = sessionsStore.nextPacketID("CLIENT");
|
||||
assertEquals(2, packetId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNextPacketID() {
|
||||
StoredMessage msgStored = new StoredMessage("Hello".getBytes(UTF_8), MqttQoS.AT_LEAST_ONCE, "/topic");
|
||||
msgStored.setClientID(TEST_CLIENT);
|
||||
|
||||
// request a first ID
|
||||
int packetId = sessionsStore.nextPacketID("CLIENT");
|
||||
sessionsStore.inFlight("CLIENT", packetId, msgStored); // simulate an inflight
|
||||
assertEquals(1, packetId);
|
||||
|
||||
// release the ID
|
||||
sessionsStore.inFlightAck("CLIENT", packetId);
|
||||
|
||||
// request a second packetID, counter restarts from 0
|
||||
packetId = sessionsStore.nextPacketID("CLIENT");
|
||||
assertEquals(1, packetId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloseShutdownCommitTask() throws InterruptedException {
|
||||
m_storageService.close();
|
||||
|
||||
// verify the executor is shutdown
|
||||
assertTrue("Storage service scheduler can't be stopped in 3 seconds",
|
||||
m_storageService.m_scheduler.awaitTermination(3, TimeUnit.SECONDS));
|
||||
assertTrue(m_storageService.m_scheduler.isTerminated());
|
||||
}
|
||||
// MapDBPersistentStore m_storageService;
|
||||
//
|
||||
// private ScheduledExecutorService scheduler;
|
||||
//
|
||||
// @Before
|
||||
// public void setUp() throws Exception {
|
||||
// scheduler = Executors.newScheduledThreadPool(1);
|
||||
//
|
||||
// cleanPersistenceFile(BrokerConstants.DEFAULT_PERSISTENT_PATH);
|
||||
// Properties props = new Properties();
|
||||
// props.setProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, BrokerConstants.DEFAULT_PERSISTENT_PATH);
|
||||
// IConfig conf = new MemoryConfig(props);
|
||||
// m_storageService = new MapDBPersistentStore(conf, scheduler);
|
||||
// m_storageService.initStore();
|
||||
// messagesStore = m_storageService.messagesStore();
|
||||
// sessionsStore = m_storageService.sessionsStore();
|
||||
// this.sessionsRepository = new SessionsRepository(sessionsStore, null);
|
||||
// }
|
||||
//
|
||||
// @After
|
||||
// public void tearDown() {
|
||||
// if (m_storageService != null) {
|
||||
// m_storageService.close();
|
||||
// }
|
||||
//
|
||||
// scheduler.shutdown();
|
||||
// cleanPersistenceFile(BrokerConstants.DEFAULT_PERSISTENT_PATH);
|
||||
// }
|
||||
//
|
||||
// static void cleanPersistenceFile(String fileName) {
|
||||
// File dbFile = new File(fileName);
|
||||
// if (dbFile.exists()) {
|
||||
// dbFile.delete();
|
||||
// new File(fileName + ".p").delete();
|
||||
// new File(fileName + ".t").delete();
|
||||
// }
|
||||
// assertFalse(dbFile.exists());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testNextPacketID_notExistingClientSession() {
|
||||
// int packetId = sessionsStore.nextPacketID("NOT_EXISTING_CLI");
|
||||
// assertEquals(1, packetId);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testNextPacketID_existingClientSession() {
|
||||
// // Force creation of inflight map for the CLIENT session
|
||||
// int packetId = sessionsStore.nextPacketID("CLIENT");
|
||||
// assertEquals(1, packetId);
|
||||
//
|
||||
// // request a second packetID
|
||||
// packetId = sessionsStore.nextPacketID("CLIENT");
|
||||
// assertEquals(2, packetId);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testNextPacketID() {
|
||||
// StoredMessage msgStored = new StoredMessage("Hello".getBytes(UTF_8), MqttQoS.AT_LEAST_ONCE, "/topic");
|
||||
// msgStored.setClientID(TEST_CLIENT);
|
||||
//
|
||||
// // request a first ID
|
||||
// int packetId = sessionsStore.nextPacketID("CLIENT");
|
||||
// sessionsStore.inFlight("CLIENT", packetId, msgStored); // simulate an inflight
|
||||
// assertEquals(1, packetId);
|
||||
//
|
||||
// // release the ID
|
||||
// sessionsStore.inFlightAck("CLIENT", packetId);
|
||||
//
|
||||
// // request a second packetID, counter restarts from 0
|
||||
// packetId = sessionsStore.nextPacketID("CLIENT");
|
||||
// assertEquals(1, packetId);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testCloseShutdownCommitTask() throws InterruptedException {
|
||||
// m_storageService.close();
|
||||
//
|
||||
// // verify the executor is shutdown
|
||||
// assertTrue("Storage service scheduler can't be stopped in 3 seconds",
|
||||
// m_storageService.m_scheduler.awaitTermination(3, TimeUnit.SECONDS));
|
||||
// assertTrue(m_storageService.m_scheduler.isTerminated());
|
||||
// }
|
||||
}
|
||||
|
||||
+96
-96
@@ -29,107 +29,107 @@ import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import static io.moquette.persistence.mapdb.MapDBPersistentStoreTest.cleanPersistenceFile;
|
||||
//import static io.moquette.persistence.mapdb.MapDBPersistentStoreTest.cleanPersistenceFile;
|
||||
import static java.time.LocalDateTime.now;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class MapDBSessionsStoreTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MapDBSessionsStoreTest.class);
|
||||
|
||||
MapDBPersistentStore storageService;
|
||||
|
||||
private ScheduledExecutorService scheduler;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
scheduler = Executors.newScheduledThreadPool(1);
|
||||
|
||||
cleanPersistenceFile(BrokerConstants.DEFAULT_PERSISTENT_PATH);
|
||||
Properties props = new Properties();
|
||||
props.setProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, BrokerConstants.DEFAULT_PERSISTENT_PATH);
|
||||
IConfig conf = new MemoryConfig(props);
|
||||
storageService = new MapDBPersistentStore(conf, scheduler);
|
||||
storageService.initStore();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if (storageService != null) {
|
||||
storageService.close();
|
||||
}
|
||||
|
||||
scheduler.shutdown();
|
||||
cleanPersistenceFile(BrokerConstants.DEFAULT_PERSISTENT_PATH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryByExpirationDate() {
|
||||
MapDBSessionsStore sessionsStore = (MapDBSessionsStore) storageService.sessionsStore();
|
||||
LocalDateTime sessionCreationTime = LocalDateTime.of(2017, 10, 1, 10, 0, 0);
|
||||
sessionsStore.trackSessionClose(sessionCreationTime, "Sensor1");
|
||||
|
||||
LocalDateTime session2CreationTime = LocalDateTime.of(2017, 11, 1, 10, 0, 0);
|
||||
sessionsStore.trackSessionClose(session2CreationTime, "Sensor2");
|
||||
|
||||
//Exercise
|
||||
LocalDateTime queryPin = LocalDateTime.of(2017, 10, 20, 10, 0, 0);
|
||||
Set<String> sessions = sessionsStore.sessionOlderThan(queryPin);
|
||||
|
||||
//Verify
|
||||
assertThat(sessions).contains("Sensor1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListAllSessionsOlderThan() {
|
||||
MapDBSessionsStore sessionsStore = (MapDBSessionsStore) storageService.sessionsStore();
|
||||
LocalDateTime sessionCreationTime = LocalDateTime.of(2017, 10, 1, 10, 0, 0);
|
||||
sessionsStore.trackSessionClose(sessionCreationTime, "Sensor1");
|
||||
|
||||
LocalDateTime session2CreationTime = LocalDateTime.of(2017, 10, 2, 10, 0, 0);
|
||||
sessionsStore.trackSessionClose(session2CreationTime, "Sensor2");
|
||||
|
||||
//Exercise
|
||||
LocalDateTime queryPin = LocalDateTime.of(2017, 10, 20, 10, 0, 0);
|
||||
Set<String> sessions = sessionsStore.sessionOlderThan(queryPin);
|
||||
|
||||
//Verify
|
||||
assertThat(sessions).contains("Sensor1", "Sensor2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetrieve1000ExpiredSessionPerformance() throws InterruptedException, ExecutionException,
|
||||
TimeoutException {
|
||||
MapDBSessionsStore sessionsStore = (MapDBSessionsStore) storageService.sessionsStore();
|
||||
|
||||
final ExecutorService executorService = Executors.newFixedThreadPool(2);
|
||||
final Future<?> future1 = executorService.submit(inserterForOffset(sessionsStore, 0));
|
||||
final Future<?> future2 = executorService.submit(inserterForOffset(sessionsStore, 5000));
|
||||
future1.get(10, TimeUnit.SECONDS);
|
||||
future2.get(10, TimeUnit.SECONDS);
|
||||
//prepare the fixture
|
||||
// for (int i = 0; i < 100000; i++) {
|
||||
// final LocalDateTime timePin = now().minusSeconds(1);
|
||||
// sessionsStore.trackSessionClose(timePin, "Sensor" + i);
|
||||
// private static final Logger LOG = LoggerFactory.getLogger(MapDBSessionsStoreTest.class);
|
||||
//
|
||||
// MapDBPersistentStore storageService;
|
||||
//
|
||||
// private ScheduledExecutorService scheduler;
|
||||
//
|
||||
// @Before
|
||||
// public void setUp() throws Exception {
|
||||
// scheduler = Executors.newScheduledThreadPool(1);
|
||||
//
|
||||
// cleanPersistenceFile(BrokerConstants.DEFAULT_PERSISTENT_PATH);
|
||||
// Properties props = new Properties();
|
||||
// props.setProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, BrokerConstants.DEFAULT_PERSISTENT_PATH);
|
||||
// IConfig conf = new MemoryConfig(props);
|
||||
// storageService = new MapDBPersistentStore(conf, scheduler);
|
||||
// storageService.initStore();
|
||||
// }
|
||||
//
|
||||
// @After
|
||||
// public void tearDown() {
|
||||
// if (storageService != null) {
|
||||
// storageService.close();
|
||||
// }
|
||||
|
||||
//Exercise
|
||||
LOG.warn("Start search");
|
||||
Set<String> sessions = sessionsStore.sessionOlderThan(now());
|
||||
LOG.warn("Finish search");
|
||||
|
||||
//Verify
|
||||
assertThat(sessions.size()).isEqualTo(10000);
|
||||
}
|
||||
|
||||
private Runnable inserterForOffset(MapDBSessionsStore sessionsStore, int start) {
|
||||
return () -> {
|
||||
//prepare the fixture
|
||||
for (int i = start; i < start + 5000; i++) {
|
||||
final LocalDateTime timePin = now().minusSeconds(1);
|
||||
sessionsStore.trackSessionClose(timePin, "Sensor" + i);
|
||||
}
|
||||
};
|
||||
}
|
||||
//
|
||||
// scheduler.shutdown();
|
||||
// cleanPersistenceFile(BrokerConstants.DEFAULT_PERSISTENT_PATH);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testQueryByExpirationDate() {
|
||||
// MapDBSessionsStore sessionsStore = (MapDBSessionsStore) storageService.sessionsStore();
|
||||
// LocalDateTime sessionCreationTime = LocalDateTime.of(2017, 10, 1, 10, 0, 0);
|
||||
// sessionsStore.trackSessionClose(sessionCreationTime, "Sensor1");
|
||||
//
|
||||
// LocalDateTime session2CreationTime = LocalDateTime.of(2017, 11, 1, 10, 0, 0);
|
||||
// sessionsStore.trackSessionClose(session2CreationTime, "Sensor2");
|
||||
//
|
||||
// //Exercise
|
||||
// LocalDateTime queryPin = LocalDateTime.of(2017, 10, 20, 10, 0, 0);
|
||||
// Set<String> sessions = sessionsStore.sessionOlderThan(queryPin);
|
||||
//
|
||||
// //Verify
|
||||
// assertThat(sessions).contains("Sensor1");
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testListAllSessionsOlderThan() {
|
||||
// MapDBSessionsStore sessionsStore = (MapDBSessionsStore) storageService.sessionsStore();
|
||||
// LocalDateTime sessionCreationTime = LocalDateTime.of(2017, 10, 1, 10, 0, 0);
|
||||
// sessionsStore.trackSessionClose(sessionCreationTime, "Sensor1");
|
||||
//
|
||||
// LocalDateTime session2CreationTime = LocalDateTime.of(2017, 10, 2, 10, 0, 0);
|
||||
// sessionsStore.trackSessionClose(session2CreationTime, "Sensor2");
|
||||
//
|
||||
// //Exercise
|
||||
// LocalDateTime queryPin = LocalDateTime.of(2017, 10, 20, 10, 0, 0);
|
||||
// Set<String> sessions = sessionsStore.sessionOlderThan(queryPin);
|
||||
//
|
||||
// //Verify
|
||||
// assertThat(sessions).contains("Sensor1", "Sensor2");
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testRetrieve1000ExpiredSessionPerformance() throws InterruptedException, ExecutionException,
|
||||
// TimeoutException {
|
||||
// MapDBSessionsStore sessionsStore = (MapDBSessionsStore) storageService.sessionsStore();
|
||||
//
|
||||
// final ExecutorService executorService = Executors.newFixedThreadPool(2);
|
||||
// final Future<?> future1 = executorService.submit(inserterForOffset(sessionsStore, 0));
|
||||
// final Future<?> future2 = executorService.submit(inserterForOffset(sessionsStore, 5000));
|
||||
// future1.get(10, TimeUnit.SECONDS);
|
||||
// future2.get(10, TimeUnit.SECONDS);
|
||||
// //prepare the fixture
|
||||
//// for (int i = 0; i < 100000; i++) {
|
||||
//// final LocalDateTime timePin = now().minusSeconds(1);
|
||||
//// sessionsStore.trackSessionClose(timePin, "Sensor" + i);
|
||||
//// }
|
||||
//
|
||||
// //Exercise
|
||||
// LOG.warn("Start search");
|
||||
// Set<String> sessions = sessionsStore.sessionOlderThan(now());
|
||||
// LOG.warn("Finish search");
|
||||
//
|
||||
// //Verify
|
||||
// assertThat(sessions.size()).isEqualTo(10000);
|
||||
// }
|
||||
//
|
||||
// private Runnable inserterForOffset(MapDBSessionsStore sessionsStore, int start) {
|
||||
// return () -> {
|
||||
// //prepare the fixture
|
||||
// for (int i = start; i < start + 5000; i++) {
|
||||
// final LocalDateTime timePin = now().minusSeconds(1);
|
||||
// sessionsStore.trackSessionClose(timePin, "Sensor" + i);
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user