Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Jun 22, 2015
2 parents 5a147f7 + 067af88 commit e7c77f2
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 7 deletions.
Expand Up @@ -57,6 +57,7 @@
import org.identityconnectors.framework.spi.Configuration;
import org.identityconnectors.framework.spi.Connector;
import org.identityconnectors.framework.spi.ConnectorClass;
import org.identityconnectors.framework.spi.PoolableConnector;
import org.identityconnectors.framework.spi.operations.AuthenticateOp;
import org.identityconnectors.framework.spi.operations.CreateOp;
import org.identityconnectors.framework.spi.operations.DeleteOp;
Expand Down Expand Up @@ -96,7 +97,7 @@
*/
@ConnectorClass(displayNameKey = "UI_CONNECTOR_NAME",
configurationClass = DummyConfiguration.class)
public class DummyConnector implements Connector, AuthenticateOp, ResolveUsernameOp, CreateOp, DeleteOp, SchemaOp,
public class DummyConnector implements PoolableConnector, AuthenticateOp, ResolveUsernameOp, CreateOp, DeleteOp, SchemaOp,
ScriptOnConnectorOp, ScriptOnResourceOp, SearchOp<Filter>, SyncOp, TestOp, UpdateAttributeValuesOp {

// We want to see if the ICF framework logging works properly
Expand Down Expand Up @@ -159,7 +160,9 @@ public void access(char[] chars) {
});
}

log.info("Dummy resource instance {0}", resource);
resource.connect();

log.info("Connected to dummy resource instance {0} ({1} connections open)", resource, resource.getConnectionCount());
}

/**
Expand All @@ -168,7 +171,14 @@ public void access(char[] chars) {
* @see Connector#dispose()
*/
public void dispose() {
resource.disconnect();
log.info("Disconnected from dummy resource instance {0} ({1} connections still open)", resource, resource.getConnectionCount());
}

@Override
public void checkAlive() {
// notthig to do. always alive.
}

/******************
* SPI Operations
Expand Down
Expand Up @@ -83,6 +83,7 @@ public class DummyResource implements DebugDumpable {
private boolean enforceSchema = true;
private boolean caseIgnoreId = false;
private boolean caseIgnoreValues = false;
private int connectionCount = 0;

private BreakMode schemaBreakMode = BreakMode.NONE;
private BreakMode getBreakMode = BreakMode.NONE;
Expand Down Expand Up @@ -259,6 +260,23 @@ public boolean isCaseIgnoreValues() {
public void setCaseIgnoreValues(boolean caseIgnoreValues) {
this.caseIgnoreValues = caseIgnoreValues;
}

public int getConnectionCount() {
return connectionCount;
}

public synchronized void connect() {
connectionCount++;
}

public synchronized void disconnect() {
connectionCount--;
}

public void assertNoConnections() {
assert connectionCount == 0 : "Dummy resource: "+connectionCount+" connections still open";
}


public DummyObjectClass getAccountObjectClass() throws ConnectException, FileNotFoundException {
if (schemaBreakMode == BreakMode.NONE) {
Expand Down
Expand Up @@ -488,4 +488,6 @@ ConstraintsCheckingResult checkConstraints(RefinedObjectClassDefinition shadowDe

void exitConstraintsCheckerCache();

public void shutdown();

}
Expand Up @@ -20,6 +20,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -497,4 +498,11 @@ public void connectorFrameworkSelfTest(OperationResult parentTestResult, Task ta
connectorFactory.selfTest(parentTestResult);
}

public void shutdown() {
for (Entry<String,ConfiguredConnectorInstanceEntry> connectorInstanceCacheEntry: connectorInstanceCache.entrySet()) {
connectorInstanceCacheEntry.getValue().connectorInstance.dispose();
}
connectorFactory.shutdown();
}

}
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import java.util.Set;

import javax.annotation.PreDestroy;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition;
Expand Down Expand Up @@ -1417,6 +1418,11 @@ public void postInit(OperationResult parentResult) {
result.computeStatus("Provisioning post-initialization failed");
result.cleanupResult();
}

@PreDestroy
public void shutdown() {
connectorManager.shutdown();
}

@Override
public ConstraintsCheckingResult checkConstraints(RefinedObjectClassDefinition shadowDefinition,
Expand Down
Expand Up @@ -96,4 +96,6 @@ public interface ConnectorFactory {
* @return
*/
String getFrameworkVersion();

void shutdown();
}
Expand Up @@ -306,5 +306,8 @@ public <T extends ShadowType> List<Change<T>> fetchChanges(ObjectClassComplexTyp

// Maybe this should be moved to ConnectorManager? In that way it can also test connector instantiation.
public void test(OperationResult parentResult);


public void dispose();

}
Expand Up @@ -44,6 +44,7 @@
import org.identityconnectors.common.security.Encryptor;
import org.identityconnectors.common.security.EncryptorFactory;
import org.identityconnectors.common.security.GuardedString;
import org.identityconnectors.framework.api.ConnectorFacadeFactory;
import org.identityconnectors.framework.api.ConnectorInfo;
import org.identityconnectors.framework.api.ConnectorInfoManager;
import org.identityconnectors.framework.api.ConnectorInfoManagerFactory;
Expand Down Expand Up @@ -799,4 +800,9 @@ static Class<? extends APIOperation> resolveApiOpClass(String opName) {
apiOpMap.put("schema", SchemaApiOp.class);
}

@Override
public void shutdown() {
ConnectorFacadeFactory.getInstance().dispose();
}

}
Expand Up @@ -3025,4 +3025,9 @@ public String getHumanReadableName() {
return connectorType.toString() + ": " + description;
}

@Override
public void dispose() {
// Nothing to do
}

}
Expand Up @@ -49,6 +49,7 @@
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
Expand Down Expand Up @@ -208,6 +209,11 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
super.initSystem(initTask, initResult);
// InternalMonitor.setTraceConnectorOperation(true);
}

@AfterClass
public static void assertCleanShutdown() throws Exception {
dummyResource.assertNoConnections();
}

@Test
public void test000Integrity() throws ObjectNotFoundException, SchemaException {
Expand Down Expand Up @@ -4528,13 +4534,12 @@ public void test890LiveSyncModifyProtectedAccount() throws Exception {
}

@Test
public void test901FailResourceNotFound() throws FileNotFoundException, JAXBException,
ObjectAlreadyExistsException, SchemaException, CommunicationException, ObjectNotFoundException,
ConfigurationException, SecurityViolationException {
TestUtil.displayTestTile("test901FailResourceNotFound");
public void test901FailResourceNotFound() throws Exception {
final String TEST_NAME = "test901FailResourceNotFound";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(TestDummy.class.getName()
+ ".test901FailResourceNotFound");
+ "." + TEST_NAME);

// WHEN
try {
Expand All @@ -4553,6 +4558,19 @@ public void test901FailResourceNotFound() throws FileNotFoundException, JAXBExce
assertSteadyResource();
}


@Test
public void test999Shutdown() throws Exception {
final String TEST_NAME = "test999Shutdown";
TestUtil.displayTestTile(TEST_NAME);

// WHEN
provisioningService.shutdown();

// THEN
dummyResource.assertNoConnections();
}

private void checkAccountShadow(ShadowType shadow, OperationResult parentResult) throws SchemaException {
checkAccountShadow(shadow, parentResult, true);
}
Expand Down

0 comments on commit e7c77f2

Please sign in to comment.