Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GEOT-3315 Memory leak in ContentEntry.state
- Loading branch information
Showing
4 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
modules/library/data/src/test/java/org/geotools/data/store/ContentEntryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* GeoTools - The Open Source Java GIS Toolkit | ||
* http://geotools.org | ||
* | ||
* (C) 2011, Open Source Geospatial Foundation (OSGeo) | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; | ||
* version 2.1 of the License. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
*/ | ||
package org.geotools.data.store; | ||
|
||
import static org.junit.Assert.assertNotSame; | ||
import static org.junit.Assert.assertSame; | ||
import static org.junit.Assert.fail; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import org.geotools.data.DefaultTransaction; | ||
import org.geotools.data.Transaction; | ||
import org.geotools.feature.NameImpl; | ||
import org.junit.Test; | ||
import org.opengis.feature.type.Name; | ||
|
||
/** | ||
* Test the behaviour of {@link ContentEntry}. | ||
* @author Mauro Bartolomeoli (mauro.bartolomeoli@geo-solutions.it) | ||
*/ | ||
public class ContentEntryTest { | ||
|
||
/** | ||
* Test that the a Transaction is removed from state when the Transaction is | ||
* closed. | ||
*/ | ||
@Test | ||
public void transactionCacheClearedOnTransactionClose() { | ||
ContentDataStore dataStore = new ContentDataStore() { | ||
|
||
@Override | ||
protected List<Name> createTypeNames() throws IOException { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected ContentFeatureSource createFeatureSource(ContentEntry entry) | ||
throws IOException { | ||
return null; | ||
} | ||
}; | ||
|
||
Transaction transaction = new DefaultTransaction(); | ||
|
||
ContentEntry entry = new ContentEntry(dataStore, new NameImpl("test")); | ||
ContentState state = entry.getState(transaction); | ||
new DiffTransactionState(state); | ||
|
||
// state is extracted from state cache | ||
assertSame(state, entry.getState(transaction)); | ||
// and contains our transaction | ||
assertSame(state.getTransaction(), transaction); | ||
|
||
try { | ||
transaction.close(); | ||
|
||
// after transaction closing, the old state has been cleared, so | ||
// a new one is built and returned | ||
ContentState stateForClosedTransaction = entry.getState(transaction); | ||
assertNotSame(stateForClosedTransaction, state); | ||
} catch (IOException e) { | ||
fail("Cannot close transaction: " + e.getLocalizedMessage()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters