Fix unit tests

This commit is contained in:
Paulo Gustavo Veiga
2022-03-23 10:56:57 -03:00
parent 63f83e879d
commit b8eadb7533
9 changed files with 144 additions and 113 deletions

View File

@@ -74,4 +74,13 @@ public class LockInfo {
this.previousTimestamp = this.timestamp;
this.timestamp = mindmap.getLastModificationTime().getTimeInMillis();
}
@Override
public String toString() {
return "LockInfo{" +
"user=" + user +
", session=" + session +
", timestamp=" + timestamp +
'}';
}
}

View File

@@ -1,20 +1,20 @@
/*
* Copyright [2022] [wisemapping]
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright [2022] [wisemapping]
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.wisemapping.service;
@@ -41,5 +41,9 @@ public interface LockManager {
long generateSession();
long verifyAndUpdateLock(@NotNull Mindmap mindmap, @NotNull User user, long session, long timestamp) throws LockException, SessionExpiredException;
@NotNull
LockInfo lock(@NotNull Mindmap mindmap, @NotNull User user, long session) throws LockException;
long verifyAndUpdateLock(@NotNull Mindmap mindmap, @NotNull User user, long session, long timestamp) throws
LockException, SessionExpiredException;
}

View File

@@ -110,9 +110,10 @@ class LockManagerImpl implements LockManager {
}
@NotNull
private LockInfo lock(@NotNull Mindmap mindmap, @NotNull User user, long session) throws LockException {
@Override
public LockInfo lock(@NotNull Mindmap mindmap, @NotNull User user, long session) throws LockException {
if (isLocked(mindmap) && !isLockedBy(mindmap, user)) {
throw new LockException("Invalid lock, this should not happen");
throw LockException.createLockLost(mindmap, user, this);
}
LockInfo result = lockInfoByMapId.get(mindmap.getId());