Tested locking
This commit is contained in:
parent
9db702aedf
commit
7f48262034
|
@ -12,7 +12,7 @@ public class GCubeTest {
|
||||||
|
|
||||||
|
|
||||||
// testContext = "/pred4s/preprod/preVRE";
|
// testContext = "/pred4s/preprod/preVRE";
|
||||||
testContext = "/gcube/devsec/devVRE";
|
// testContext = "/gcube/devsec/devVRE";
|
||||||
|
|
||||||
|
|
||||||
System.out.println("TEST CONTEXT = "+testContext);
|
System.out.println("TEST CONTEXT = "+testContext);
|
||||||
|
|
|
@ -441,6 +441,10 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
||||||
doc.setTheDocument(Document.parse(docWrapper.getValueCTX().jsonString()));
|
doc.setTheDocument(Document.parse(docWrapper.getValueCTX().jsonString()));
|
||||||
|
|
||||||
doc = onUpdate(doc);
|
doc = onUpdate(doc);
|
||||||
|
}catch (Throwable t){
|
||||||
|
log.warn("Unexpected Exception while trying to registering fileset on {}.",id,t);
|
||||||
|
log.debug("Request was {}",request);
|
||||||
|
log.debug("Complete doc was {} ",doc);
|
||||||
}finally {
|
}finally {
|
||||||
return unlockAndUpdate(doc);
|
return unlockAndUpdate(doc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,111 @@
|
||||||
|
package org.gcube.application.geoportal.service.engine.mongo;
|
||||||
|
|
||||||
|
import org.bson.Document;
|
||||||
|
import org.gcube.application.cms.plugins.faults.EventException;
|
||||||
|
import org.gcube.application.cms.plugins.faults.StepException;
|
||||||
|
import org.gcube.application.cms.tests.TokenSetter;
|
||||||
|
import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel;
|
||||||
|
import org.gcube.application.geoportal.common.faults.StorageException;
|
||||||
|
import org.gcube.application.geoportal.common.model.document.Lock;
|
||||||
|
import org.gcube.application.geoportal.common.model.document.Project;
|
||||||
|
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||||
|
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
|
||||||
|
import org.gcube.application.geoportal.common.model.useCaseDescriptor.Field;
|
||||||
|
import org.gcube.application.geoportal.common.utils.FileSets;
|
||||||
|
import org.gcube.application.geoportal.common.utils.StorageUtils;
|
||||||
|
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
||||||
|
import org.gcube.application.geoportal.service.BasicServiceTestUnit;
|
||||||
|
import org.gcube.application.geoportal.service.model.internal.faults.*;
|
||||||
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||||
|
import org.geotoolkit.referencing.operation.provider.PolarStereographic;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static junit.framework.TestCase.*;
|
||||||
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
|
||||||
|
public class LockTests extends BasicServiceTestUnit {
|
||||||
|
|
||||||
|
String profileID = "profiledConcessioni";
|
||||||
|
ProfiledMongoManager manager= null;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void inits() throws RegistrationException, ConfigurationException {
|
||||||
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||||
|
TokenSetter.set(GCubeTest.getContext());
|
||||||
|
manager = new ProfiledMongoManager(profileID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLocking() throws StepException, EventException, IOException, ProjectLockedException, ProjectNotFoundException, InvalidLockException {
|
||||||
|
Project p = manager.registerNew(new Document("dummyField","dummyValue"));
|
||||||
|
// lock
|
||||||
|
p= manager.lock(p.getId(),"Testing");
|
||||||
|
|
||||||
|
assertNotNull(p.getLock());
|
||||||
|
assertNotNull(p.getLock().getId());
|
||||||
|
assertNotNull(p.getLock().getInfo());
|
||||||
|
assertTrue(p.getLock().getOperation().equals("Testing"));
|
||||||
|
|
||||||
|
try{
|
||||||
|
Lock l =p.getLock();
|
||||||
|
System.out.println("Lock is "+l);
|
||||||
|
p = manager.lock(p.getId(),"Should Fail");
|
||||||
|
fail("Expected Lock exception. New Lock is "+p.getLock());
|
||||||
|
}catch(ProjectLockedException e){
|
||||||
|
// expected lock exception
|
||||||
|
System.out.println("Successfully blocked invalid lock operation");
|
||||||
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
|
Lock l =p.getLock();
|
||||||
|
System.out.println("Lock is "+l);
|
||||||
|
manager.update(p.getId(),new Document("should","fail"));
|
||||||
|
fail("Expected Lock exception. New Lock is "+p.getLock());
|
||||||
|
}catch (ProjectLockedException e){
|
||||||
|
// expected lock exception
|
||||||
|
System.out.println("Successfully blocked invalid edit operation");
|
||||||
|
}
|
||||||
|
|
||||||
|
manager.unlockAndUpdate(p);
|
||||||
|
|
||||||
|
manager.update(p.getId(),new Document("should","fail"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnlock() throws StepException, EventException, IOException, ProjectNotFoundException, ProjectLockedException, InvalidLockException, DeletionException, ConfigurationException, StorageHubException, StorageException {
|
||||||
|
MongoManagerI<Project> managerInterface = manager;
|
||||||
|
// create
|
||||||
|
Project p = managerInterface.registerNew(new Document("dummyField","dummyValue"));
|
||||||
|
checkIsLockCleaned(p.getId());
|
||||||
|
|
||||||
|
// edit
|
||||||
|
p=managerInterface.update(p.getId(),new Document("some","field"));
|
||||||
|
checkIsLockCleaned(p.getId());
|
||||||
|
|
||||||
|
// register fileset
|
||||||
|
FileSets.RequestBuilder builder = FileSets.build(
|
||||||
|
"$.relazioneScavo","fileset","relazioneScavo."+ Field.CHILDREN+"[?(@.fileset)]");
|
||||||
|
StorageUtils s= new StorageUtils();
|
||||||
|
builder.add(
|
||||||
|
s.putOntoStorage(new File(TestConcessioniModel.getBaseFolder(),"pos.shp"),"pos.shp"));
|
||||||
|
|
||||||
|
p= managerInterface.registerFileSet(p.getId(),builder.getTheRequest());
|
||||||
|
checkIsLockCleaned(p.getId());
|
||||||
|
|
||||||
|
// delete fileset
|
||||||
|
p=managerInterface.deleteFileSet(p.getId(),"$.relazioneScavo.fileset",false);
|
||||||
|
checkIsLockCleaned(p.getId());
|
||||||
|
|
||||||
|
// perform step
|
||||||
|
p=managerInterface.performStep(p.getId(),"SUBMIT DRAFT",new Document());
|
||||||
|
checkIsLockCleaned(p.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkIsLockCleaned(String id) throws ProjectNotFoundException {
|
||||||
|
assertNull(manager.getByID(id).getLock());
|
||||||
|
}
|
||||||
|
}
|
|
@ -40,7 +40,8 @@ public class ProfiledConcessioniTests extends AbstractProfiledDocumentsTests{
|
||||||
doc = upload(
|
doc = upload(
|
||||||
new StorageUtils(),
|
new StorageUtils(),
|
||||||
doc.getId(),
|
doc.getId(),
|
||||||
"posizionamentoScavo","fileset",
|
"posizionamentoScavo",
|
||||||
|
"fileset",
|
||||||
"posizionamentoScavo."+ Field.CHILDREN+"[?(@.fileset)]",
|
"posizionamentoScavo."+ Field.CHILDREN+"[?(@.fileset)]",
|
||||||
null,
|
null,
|
||||||
RegisterFileSetRequest.ClashOptions.MERGE_EXISTING,
|
RegisterFileSetRequest.ClashOptions.MERGE_EXISTING,
|
||||||
|
|
Loading…
Reference in New Issue