Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset SettingsManager's instance when calling cleanup #461

Open
srstsavage opened this issue Aug 22, 2016 · 1 comment
Open

Reset SettingsManager's instance when calling cleanup #461

srstsavage opened this issue Aug 22, 2016 · 1 comment

Comments

@srstsavage
Copy link
Contributor

SettingsManager provides the cleanup method:

/**
 * Clean up this SettingsManager. All subsequent calls to this class are
 * undefined.
 */
public abstract void cleanup();

This method is purely abstract and does not unset SettingsManager's instance property, used in getInstance():

    /**
     * Gets the singleton instance of the SettingsManager.
     * <p/>
     *
     * @return the settings manager
     *         <p/>
     * @throws ConfigurationException
     *             if no implementation can be found
     */
    public static SettingsManager getInstance() throws ConfigurationException {
        if (instance == null) {
            creationLock.lock();
            try {
                if (instance == null) {
                    instance = createInstance();
                }
            } finally {
                creationLock.unlock();
            }
        }
        return instance;
    }

I'm running into this problem when trying to create a second integration test suite. SOS40ComplianceTestSuite runs SettingsManager.getInstance().cleanup() in its @AfterClass, which invalidates the SettingsManager for any tests running after the suite.

    @AfterClass
    public static void cleanup() {
        SettingsManager.getInstance().cleanup();
    }

If SettingsManager.getInstance().cleanup() set instance = null then I believe future calls to SettingsManager.getInstance() would reinitialize the SettingsManager, allowing for further usage.

@srstsavage
Copy link
Contributor Author

Just a note, if it's decided that SettingsManager shouldn't be able to reinitialize after cleanup() is called we should at least catch when getConnection() is called after cleanup(). Right now the message is confusing : Unknown service requested [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider]

Example stacktrace:

java.lang.RuntimeException: org.n52.sos.ds.ConnectionProviderException: org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:201)
    at org.hibernate.internal.AbstractSessionImpl.getJdbcConnectionAccess(AbstractSessionImpl.java:341)
    at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.<init>(JdbcCoordinatorImpl.java:114)
    at org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl.<init>(TransactionCoordinatorImpl.java:89)
    at org.hibernate.internal.SessionImpl.<init>(SessionImpl.java:258)
    at org.hibernate.internal.SessionFactoryImpl$SessionBuilderImpl.openSession(SessionFactoryImpl.java:1589)
    at org.hibernate.internal.SessionFactoryImpl.openSession(SessionFactoryImpl.java:999)
    at org.n52.sos.config.sqlite.SQLiteSessionFactoryForTesting.getConnection(SQLiteSessionFactoryForTesting.java:72)
    at org.n52.sos.config.sqlite.SQLiteSessionFactoryForTesting.getConnection(SQLiteSessionFactoryForTesting.java:46)
    at org.n52.sos.config.sqlite.SQLiteManager.execute(SQLiteManager.java:81)
    at org.n52.sos.config.sqlite.SQLiteSettingsManager.execute(SQLiteSettingsManager.java:127)
    at org.n52.sos.config.sqlite.ExtensionEnabledSQLiteSettingsManager.execute(ExtensionEnabledSQLiteSettingsManager.java:86)
    at org.n52.sos.config.sqlite.ExtensionEnabledSQLiteSettingsManager.getActiveStaticCapabilities(ExtensionEnabledSQLiteSettingsManager.java:128)
    at org.n52.sos.config.sqlite.ExtensionEnabledSQLiteSettingsManager.isStaticCapabilitiesActive(ExtensionEnabledSQLiteSettingsManager.java:162)
    at org.n52.sos.ds.GetCapabilitiesDAO.getCapabilities(GetCapabilitiesDAO.java:204)
    at org.n52.sos.request.operator.SosGetCapabilitiesOperatorV20.receive(SosGetCapabilitiesOperatorV20.java:71)
    at org.n52.sos.request.operator.SosGetCapabilitiesOperatorV20.receive(SosGetCapabilitiesOperatorV20.java:53)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant