Browse code

[mail-api] EORIS-10 Fix: don't timeout when updating a folder with the same name, just touch the item

Thomas Cataldo authored on 12/08/2019 13:40:44
Showing 2 changed files
... ...
@@ -83,9 +83,9 @@ import net.bluemind.backend.mail.replica.api.MailboxAnnotation;
83 83
 import net.bluemind.backend.mail.replica.api.MailboxReplica;
84 84
 import net.bluemind.backend.mail.replica.api.MailboxReplicaRootDescriptor;
85 85
 import net.bluemind.backend.mail.replica.api.MailboxReplicaRootDescriptor.Namespace;
86
-import net.bluemind.backend.mail.replica.api.utils.Subtree;
87 86
 import net.bluemind.backend.mail.replica.api.MailboxSub;
88 87
 import net.bluemind.backend.mail.replica.api.QuotaRoot;
88
+import net.bluemind.backend.mail.replica.api.utils.Subtree;
89 89
 import net.bluemind.backend.mail.replica.service.ReplicationEvents;
90 90
 import net.bluemind.backend.mail.replica.service.tests.ReplicationEventsRecorder.Hierarchy;
91 91
 import net.bluemind.backend.mail.replica.utils.SubtreeContainer;
... ...
@@ -1147,6 +1147,39 @@ public class ReplicationStackTests extends AbstractRollingReplicationTests {
1147 1147
 		addDraft(foundItem, ids.globalCounter + 2);
1148 1148
 	}
1149 1149
 
1150
+	@Test
1151
+	public void renameFolderToSameName() throws IMAPException, InterruptedException, IOException {
1152
+		IServiceProvider clientProv = provider();
1153
+		IMailboxFolders mboxesApi = clientProv.instance(IMailboxFolders.class, partition, mboxRoot);
1154
+		List<ItemValue<MailboxFolder>> allBoxes = mboxesApi.all();
1155
+		ItemValue<MailboxFolder> inbox = null;
1156
+		for (ItemValue<MailboxFolder> box : allBoxes) {
1157
+			System.out.println("On name " + box.value.name);
1158
+			if (box.value.name.equals("INBOX")) {
1159
+				inbox = box;
1160
+				break;
1161
+			}
1162
+		}
1163
+		assertNotNull(inbox);
1164
+		MailboxReplica toCreate = new MailboxReplica();
1165
+		long time = System.currentTimeMillis() / 1000;
1166
+		toCreate.name = "create" + time;
1167
+		IOfflineMgmt idAllocator = provider().instance(IOfflineMgmt.class, domainUid, userUid);
1168
+		IdRange ids = idAllocator.allocateOfflineIds(3);
1169
+		ItemIdentifier created = mboxesApi.createForHierarchy(ids.globalCounter, toCreate);
1170
+		System.out.println("Got a create of version " + created.version);
1171
+		ContainerChangeset<Long> changed = mboxesApi.changesetById(created.version - 1);
1172
+		long newItemId = changed.created.get(0);
1173
+		System.out.println("From changelog: itemId should be " + newItemId);
1174
+		ItemValue<MailboxFolder> foundItem = mboxesApi.getCompleteById(newItemId);
1175
+		System.out.println("Found " + foundItem.value.name);
1176
+		addDraft(foundItem, ids.globalCounter + 1);
1177
+
1178
+		Ack updated = mboxesApi.updateById(foundItem.internalId, foundItem.value);
1179
+		System.err.println("version after update: " + updated.version + " for " + foundItem.value.name);
1180
+		assertTrue(updated.version > foundItem.version);
1181
+	}
1182
+
1150 1183
 	private CountDownLatch expectMessage(String vertxAddress) {
1151 1184
 		return expectMessages(vertxAddress, 1, msg -> true);
1152 1185
 	}
... ...
@@ -130,9 +130,16 @@ public class ImapReplicatedMailboxesService extends BaseReplicatedMailboxesServi
130 130
 		}
131 131
 		final String fnOld = oldName;
132 132
 		final String fnNew = newName;
133
+
134
+		if (fnOld.equals(fnNew)) {
135
+			logger.warn("Rename attempt to same name '{}'");
136
+			storeService.touch(current.uid);
137
+			ItemValue<MailboxFolder> touched = getCompleteById(id);
138
+			return Ack.create(touched.version);
139
+		}
133 140
 		CompletableFuture<ItemIdentifier> future = ReplicationEvents.onSubtreeUpdate(toWatch);
134 141
 		return imapContext.withImapClient((sc, fast) -> {
135
-			logger.info("Rename attempt of {} to {}", fnOld, fnNew);
142
+			logger.info("Rename attempt of '{}' to '{}'", fnOld, fnNew);
136 143
 			selectInbox(sc, fast);
137 144
 			sc.rename(fnOld, fnNew);
138 145
 			long version = future.get(10, TimeUnit.SECONDS).version;