Added unit test and fix for issue #12, due to bad topic in publish message after a late subscription and messages retained in DB.

This commit is contained in:
andrea
2013-08-28 10:26:02 +02:00
parent b1ee353ea8
commit afcc20f483
3 changed files with 54 additions and 4 deletions
@@ -26,10 +26,12 @@ public class HawtDBStorageService implements IStorageService {
public static class StoredMessage implements Serializable {
AbstractMessage.QOSType m_qos;
byte[] m_payload;
String m_topic;
StoredMessage(byte[] message, AbstractMessage.QOSType qos) {
StoredMessage(byte[] message, AbstractMessage.QOSType qos, String topic) {
m_qos = qos;
m_payload = message;
m_topic = topic;
}
AbstractMessage.QOSType getQos() {
@@ -39,6 +41,10 @@ public class HawtDBStorageService implements IStorageService {
byte[] getPayload() {
return m_payload;
}
String getTopic() {
return m_topic;
}
}
@@ -132,7 +138,7 @@ public class HawtDBStorageService implements IStorageService {
m_retainedStore.remove(topic);
} else {
//store the message to the topic
m_retainedStore.put(topic, new StoredMessage(message, qos));
m_retainedStore.put(topic, new StoredMessage(message, qos, topic));
}
}
@@ -400,7 +400,7 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
for (StoredMessage storedMsg : messages) {
//fire the as retained the message
LOG.debug("Inserting NotifyEvent into outbound for topic " + topic);
notify(new NotifyEvent(newSubscription.getClientId(), topic, storedMsg.getQos(), storedMsg.getPayload(), true));
notify(new NotifyEvent(newSubscription.getClientId(), storedMsg.getTopic(), storedMsg.getQos(), storedMsg.getPayload(), true));
}
}
@@ -408,7 +408,7 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
LOG.debug("processSubscribe invoked");
for (SubscribeMessage.Couple req : msg.subscriptions()) {
QOSType qos = AbstractMessage.QOSType.fromByte(req.getQos());
QOSType qos = AbstractMessage.QOSType.values()[req.getQos()];
Subscription newSubscription = new Subscription(clientID, req.getTopic(), qos, cleanSession);
subscribeSingleTopic(newSubscription, req.getTopic());
}