use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class CacheManagerIT method testCache.
// private final StringBuffer longString = new StringBuffer();
public void testCache() {
// Make sure we have a cache first...
// TODO sbarkdull, need to get real session in
ICacheManager cacheManager = PentahoSystem.getCacheManager(null);
// here
Assert.assertNotNull(cacheManager);
Assert.assertTrue(cacheManager.cacheEnabled());
// Test Session Based Caching
// $NON-NLS-1$ //$NON-NLS-2$
StandaloneSession userSession1 = new StandaloneSession("Standalone Session", "1234-5678-90");
// $NON-NLS-1$ //$NON-NLS-2$
StandaloneSession userSession2 = new StandaloneSession("Standalone Session", "abc-def-ghi-jkl");
// ================================ Create Objects
// User Objects
// Cache any-old String...
// $NON-NLS-1$
String user1StringObject = "User1's String Object";
// Make sure we can cache these Document objects...
Document user1Document = DocumentHelper.createDocument();
// $NON-NLS-1$
Element user1RootNode = user1Document.addElement("user1");
// $NON-NLS-1$
Element user1FileNode = user1RootNode.addElement("file");
// $NON-NLS-1$ //$NON-NLS-2$
user1FileNode.addAttribute("name", "test");
String user1CompareXMLOriginal = user1Document.asXML();
// User2's Objects
// Cache any-old String...
// $NON-NLS-1$
String user2StringObject = "User2's String Object";
Document user2Document = DocumentHelper.createDocument();
// $NON-NLS-1$
Element user2RootNode = user2Document.addElement("user2");
// $NON-NLS-1$
Element user2FileNode = user2RootNode.addElement("folder");
// $NON-NLS-1$ //$NON-NLS-2$
user2FileNode.addAttribute("name", "test2");
String user2CompareXMLOriginal = user2Document.asXML();
// Global Objects
Integer globalInt = new Integer(372);
// $NON-NLS-1$
BigDecimal globalBigDecimal = new BigDecimal("2342.123334444211");
StringBuffer globalStringBuffer = new StringBuffer();
// $NON-NLS-1$
globalStringBuffer.append("This is a really long string to stick in a string buffer");
// Ok - we now have some stuff to jam into the cache.
// $NON-NLS-1$
cacheManager.putInSessionCache(userSession1, "StringObject", user1StringObject);
// $NON-NLS-1$
cacheManager.putInSessionCache(userSession1, "repoDoc", user1Document);
// $NON-NLS-1$
cacheManager.putInSessionCache(userSession2, "StringObject", user2StringObject);
// $NON-NLS-1$
cacheManager.putInSessionCache(userSession2, "repoDoc", user2Document);
// Get them back out
// $NON-NLS-1$
Object user1CachedStringObject = cacheManager.getFromSessionCache(userSession1, "StringObject");
Assert.assertEquals(user1StringObject, (String) user1CachedStringObject);
// $NON-NLS-1$
Object user1CachedDocument = cacheManager.getFromSessionCache(userSession1, "repoDoc");
String user1CompareXMLCached = ((Document) user1CachedDocument).asXML();
Assert.assertEquals(user1CompareXMLOriginal, user1CompareXMLCached);
// $NON-NLS-1$
Object user2CachedStringObject = cacheManager.getFromSessionCache(userSession2, "StringObject");
Assert.assertEquals(user2StringObject, (String) user2CachedStringObject);
// $NON-NLS-1$
Object user2CachedDocument = cacheManager.getFromSessionCache(userSession2, "repoDoc");
String user2CompareXMLCached = ((Document) user2CachedDocument).asXML();
Assert.assertEquals(user2CompareXMLOriginal, user2CompareXMLCached);
// OK - We've verified that their objects are unique to each individual
// user.
// Test Removals from session only
// Remove a single user-session based object.
// $NON-NLS-1$
cacheManager.removeFromSessionCache(userSession1, "StringObject");
// Try to get it back anyway.
// $NON-NLS-1$
Object notThere = cacheManager.getFromSessionCache(userSession1, "StringObject");
Assert.assertNull(notThere);
// Make sure that User2 is unaffected
// $NON-NLS-1$
Object shouldBeThere = cacheManager.getFromSessionCache(userSession2, "StringObject");
Assert.assertNotNull(shouldBeThere);
// Kill user1's session
cacheManager.killSessionCache(userSession1);
// $NON-NLS-1$
notThere = cacheManager.getFromSessionCache(userSession1, "repoDoc");
Assert.assertNull(notThere);
// Make sure that User2 is still unaffected
// $NON-NLS-1$
shouldBeThere = cacheManager.getFromSessionCache(userSession2, "StringObject");
Assert.assertNotNull(shouldBeThere);
// Test Global Caching
// Put stuff in
// $NON-NLS-1$
cacheManager.putInGlobalCache("globalIntegerKey", globalInt);
// $NON-NLS-1$
cacheManager.putInGlobalCache("globalBigDecimalKey", globalBigDecimal);
// $NON-NLS-1$
cacheManager.putInGlobalCache("globalStringBufferKey", globalStringBuffer);
// $NON-NLS-1$
Object cachedGlobalInt = cacheManager.getFromGlobalCache("globalIntegerKey");
Assert.assertEquals(globalInt, cachedGlobalInt);
// $NON-NLS-1$
Object cachedGlobalBigDecimal = cacheManager.getFromGlobalCache("globalBigDecimalKey");
Assert.assertEquals(globalBigDecimal, cachedGlobalBigDecimal);
// $NON-NLS-1$
Object cachedGlobalStringBuffer = cacheManager.getFromGlobalCache("globalStringBufferKey");
Assert.assertEquals(globalStringBuffer, cachedGlobalStringBuffer);
// Test clear all session-based keys. This should leave the global stuff
// alone.
cacheManager.killSessionCaches();
// $NON-NLS-1$
notThere = cacheManager.getFromSessionCache(userSession2, "StringObject");
Assert.assertNull(notThere);
// $NON-NLS-1$
notThere = cacheManager.getFromSessionCache(userSession2, "repoDoc");
Assert.assertNull(notThere);
// $NON-NLS-1$
shouldBeThere = cacheManager.getFromGlobalCache("globalIntegerKey");
Assert.assertNotNull(shouldBeThere);
// Totally clear out the cache.
cacheManager.clearCache();
// $NON-NLS-1$
notThere = cacheManager.getFromGlobalCache("globalIntegerKey");
Assert.assertNull(notThere);
// $NON-NLS-1$
notThere = cacheManager.getFromGlobalCache("globalBigDecimalKey");
Assert.assertNull(notThere);
// $NON-NLS-1$
notThere = cacheManager.getFromGlobalCache("globalStringBufferKey");
Assert.assertNull(notThere);
cacheManager.addCacheRegion(ICacheManager.GLOBAL);
// Assumes cache size is set to 2000 objects maximum.
for (int i = 0; i < 10000; i++) {
// $NON-NLS-1$
String someCachedString = "This is the string to cache " + i;
// $NON-NLS-1$
String someCachedKey = "SomeCachedKey" + i;
if ((i % 1000) == 0) {
sleep(5);
}
cacheManager.putInGlobalCache(someCachedKey, someCachedString);
}
// Let cache stabalize, and decide what hasn't been used for a while.
// 15 seconds should do it.
sleep(15);
// Get first item from the cache...
// $NON-NLS-1$
shouldBeThere = cacheManager.getFromGlobalCache("SomeCachedKey1");
// $NON-NLS-1$
Assert.assertEquals(shouldBeThere, "This is the string to cache 1");
// Get middle item from the cache...
// $NON-NLS-1$
shouldBeThere = cacheManager.getFromGlobalCache("SomeCachedKey5000");
// $NON-NLS-1$
Assert.assertEquals(shouldBeThere, "This is the string to cache 5000");
// Get last item from the cache...
// $NON-NLS-1$
shouldBeThere = cacheManager.getFromGlobalCache("SomeCachedKey999");
// $NON-NLS-1$
Assert.assertEquals(shouldBeThere, "This is the string to cache 999");
// Clear cache again...
cacheManager.clearCache();
// Make sure...
// $NON-NLS-1$
notThere = cacheManager.getFromGlobalCache("SomeCachedKey2");
Assert.assertNull(notThere);
// $NON-NLS-1$
notThere = cacheManager.getFromGlobalCache("SomeCachedKey5002");
Assert.assertNull(notThere);
// $NON-NLS-1$
notThere = cacheManager.getFromGlobalCache("SomeCachedKey998");
Assert.assertNull(notThere);
// Done with tests.
}
use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class CacheManagerWithRegionIT method testCacheRegion.
// private final StringBuffer longString = new StringBuffer();
public void testCacheRegion() {
// Make sure we have a cache first...
// TODO sbarkdull, need to get real session in
ICacheManager cacheManager = PentahoSystem.getCacheManager(null);
// here
Assert.assertNotNull(cacheManager);
Assert.assertTrue(cacheManager.cacheEnabled());
// Test Session Based Caching
// $NON-NLS-1$ //$NON-NLS-2$
StandaloneSession userSession1 = new StandaloneSession("Standalone Session", "1234-5678-90");
// $NON-NLS-1$ //$NON-NLS-2$
StandaloneSession userSession2 = new StandaloneSession("Standalone Session", "abc-def-ghi-jkl");
// ================================ Create Objects
// User Objects
// Cache any-old String...
// $NON-NLS-1$
String user1StringObject = "User1's String Object";
// Make sure we can cache these Document objects...
Document user1Document = DocumentHelper.createDocument();
// $NON-NLS-1$
Element user1RootNode = user1Document.addElement("user1");
// $NON-NLS-1$
Element user1FileNode = user1RootNode.addElement("file");
// $NON-NLS-1$ //$NON-NLS-2$
user1FileNode.addAttribute("name", "test");
String user1CompareXMLOriginal = user1Document.asXML();
// User2's Objects
// Cache any-old String...
// $NON-NLS-1$
String user2StringObject = "User2's String Object";
Document user2Document = DocumentHelper.createDocument();
// $NON-NLS-1$
Element user2RootNode = user2Document.addElement("user2");
// $NON-NLS-1$
Element user2FileNode = user2RootNode.addElement("folder");
// $NON-NLS-1$ //$NON-NLS-2$
user2FileNode.addAttribute("name", "test2");
String user2CompareXMLOriginal = user2Document.asXML();
// Global Objects
Integer globalInt = new Integer(372);
// $NON-NLS-1$
BigDecimal globalBigDecimal = new BigDecimal("2342.123334444211");
StringBuffer globalStringBuffer = new StringBuffer();
// $NON-NLS-1$
globalStringBuffer.append("This is a really long string to stick in a string buffer");
cacheManager.putInRegionCache(userSession1.getId(), "StringObject", user1StringObject);
// $NON-NLS-1$
cacheManager.putInRegionCache(userSession1.getId(), "repoDoc", user1Document);
// $NON-NLS-1$
cacheManager.putInRegionCache(userSession2.getId(), "StringObject", user2StringObject);
// $NON-N
cacheManager.putInRegionCache(userSession2.getId(), "repoDoc", user2Document);
// Get them back out
// $NON-NLS-1$
Object user1CachedStringObject = cacheManager.getFromRegionCache(userSession1.getId(), "StringObject");
Assert.assertNull(user1CachedStringObject);
// $NON-NLS-1$
Object user1CachedDocument = cacheManager.getFromRegionCache(userSession1.getId(), "repoDoc");
Assert.assertNull(user1CachedDocument);
// $NON-NLS-1$
Object user2CachedStringObject = cacheManager.getFromRegionCache(userSession2.getId(), "StringObject");
Assert.assertNull(user2CachedStringObject);
// $NON-NLS-1$
Object user2CachedDocument = cacheManager.getFromRegionCache(userSession2.getId(), "repoDoc");
Assert.assertNull(user2CachedDocument);
cacheManager.addCacheRegion(userSession1.getId());
cacheManager.addCacheRegion(userSession2.getId());
// Ok - we now have some stuff to jam into the cache.
cacheManager.putInRegionCache(userSession1.getId(), "StringObject", user1StringObject);
// $NON-NLS-1$
cacheManager.putInRegionCache(userSession1.getId(), "repoDoc", user1Document);
// $NON-NLS-1$
cacheManager.putInRegionCache(userSession2.getId(), "StringObject", user2StringObject);
// $NON-NLS-1$
cacheManager.putInRegionCache(userSession2.getId(), "repoDoc", user2Document);
// Get them back out
// $NON-NLS-1$
Object user1CachedStringObject1 = cacheManager.getFromRegionCache(userSession1.getId(), "StringObject");
Assert.assertEquals(user1StringObject, (String) user1CachedStringObject1);
// $NON-NLS-1$
Object user1CachedDocument1 = cacheManager.getFromRegionCache(userSession1.getId(), "repoDoc");
String user1CompareXMLCached1 = ((Document) user1CachedDocument1).asXML();
Assert.assertEquals(user1CompareXMLOriginal, user1CompareXMLCached1);
// $NON-NLS-1$
Object user2CachedStringObject1 = cacheManager.getFromRegionCache(userSession2.getId(), "StringObject");
Assert.assertEquals(user2StringObject, (String) user2CachedStringObject1);
// $NON-NLS-1$
Object user2CachedDocument1 = cacheManager.getFromRegionCache(userSession2.getId(), "repoDoc");
String user2CompareXMLCached1 = ((Document) user2CachedDocument1).asXML();
Assert.assertEquals(user2CompareXMLOriginal, user2CompareXMLCached1);
// OK - We've verified that their objects are unique to each individual
// user.
// Test Removals from session only
// Remove a single user-session based object.
// $NON-NLS-1$
cacheManager.removeFromRegionCache(userSession1.getId(), "StringObject");
// Try to get it back anyway.
// $NON-NLS-1$
Object notThere = cacheManager.getFromRegionCache(userSession1.getId(), "StringObject");
Assert.assertNull(notThere);
// Make sure that User2 is unaffected
// $NON-NLS-1$
Object shouldBeThere = cacheManager.getFromRegionCache(userSession2.getId(), "StringObject");
Assert.assertNotNull(shouldBeThere);
// Kill user1's session
cacheManager.removeRegionCache(userSession1.getId());
// $NON-NLS-1$
notThere = cacheManager.getFromRegionCache(userSession1.getId(), "repoDoc");
Assert.assertNull(notThere);
// Make sure that User2 is still unaffected
// $NON-NLS-1$
shouldBeThere = cacheManager.getFromRegionCache(userSession2.getId(), "StringObject");
Assert.assertNotNull(shouldBeThere);
// Test Global Caching
cacheManager.addCacheRegion("Global");
// Put stuff in
// $NON-NLS-1$
cacheManager.putInRegionCache("Global", "globalIntegerKey", globalInt);
// $NON-NLS-1$
cacheManager.putInRegionCache("Global", "globalBigDecimalKey", globalBigDecimal);
// $NON-NLS-1$
cacheManager.putInRegionCache("Global", "globalStringBufferKey", globalStringBuffer);
// $NON-NLS-1$
Object cachedGlobalInt = cacheManager.getFromRegionCache("Global", "globalIntegerKey");
Assert.assertEquals(globalInt, cachedGlobalInt);
// $NON-NLS-1$
Object cachedGlobalBigDecimal = cacheManager.getFromRegionCache("Global", "globalBigDecimalKey");
Assert.assertEquals(globalBigDecimal, cachedGlobalBigDecimal);
// $NON-NLS-1$
Object cachedGlobalStringBuffer = cacheManager.getFromRegionCache("Global", "globalStringBufferKey");
Assert.assertEquals(globalStringBuffer, cachedGlobalStringBuffer);
// Test clear all session-based keys. This should leave the global stuff
// alone.
cacheManager.removeRegionCache(userSession2.getId());
// $NON-NLS-1$
notThere = cacheManager.getFromRegionCache(userSession2.getId(), "StringObject");
Assert.assertNull(notThere);
// $NON-NLS-1$
notThere = cacheManager.getFromRegionCache(userSession2.getId(), "repoDoc");
Assert.assertNull(notThere);
// $NON-NLS-1$
shouldBeThere = cacheManager.getFromRegionCache("Global", "globalIntegerKey");
Assert.assertNotNull(shouldBeThere);
// Totally clear out the cache.
cacheManager.clearCache();
// $NON-NLS-1$
notThere = cacheManager.getFromRegionCache("Global", "globalIntegerKey");
Assert.assertNull(notThere);
// $NON-NLS-1$
notThere = cacheManager.getFromRegionCache("Global", "globalBigDecimalKey");
Assert.assertNull(notThere);
// $NON-NLS-1$
notThere = cacheManager.getFromRegionCache("Global", "globalStringBufferKey");
Assert.assertNull(notThere);
cacheManager.addCacheRegion("Global");
// Assumes cache size is set to 2000 objects maximum.
for (int i = 0; i < 10000; i++) {
// $NON-NLS-1$
String someCachedString = "This is the string to cache " + i;
// $NON-NLS-1$
String someCachedKey = "SomeCachedKey" + i;
if ((i % 1000) == 0) {
sleep(5);
}
cacheManager.putInRegionCache("Global", someCachedKey, someCachedString);
}
// Let cache stabalize, and decide what hasn't been used for a while.
// 15 seconds should do it.
sleep(15);
// Get first item from the cache...
// $NON-NLS-1$
shouldBeThere = cacheManager.getFromRegionCache("Global", "SomeCachedKey1");
// $NON-NLS-1$
Assert.assertEquals(shouldBeThere, "This is the string to cache 1");
// Get middle item from the cache...
// $NON-NLS-1$
shouldBeThere = cacheManager.getFromRegionCache("Global", "SomeCachedKey5000");
// $NON-NLS-1$
Assert.assertEquals(shouldBeThere, "This is the string to cache 5000");
// Get last item from the cache...
// $NON-NLS-1$
shouldBeThere = cacheManager.getFromRegionCache("Global", "SomeCachedKey999");
// $NON-NLS-1$
Assert.assertEquals(shouldBeThere, "This is the string to cache 999");
// Clear cache again...
cacheManager.clearCache();
// Make sure...
// $NON-NLS-1$
notThere = cacheManager.getFromRegionCache("Global", "SomeCachedKey2");
Assert.assertNull(notThere);
// $NON-NLS-1$
notThere = cacheManager.getFromRegionCache("Global", "SomeCachedKey5002");
Assert.assertNull(notThere);
// $NON-NLS-1$
notThere = cacheManager.getFromRegionCache("Global", "SomeCachedKey998");
Assert.assertNull(notThere);
// Done with tests.
}
use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class ConnectionIT method testMDX_VFS_zipped_Schema.
/**
* This test currently fails, due to Mondrian not understanding the catalog URL. I'm guessing we're not using the
* latest mondrian libs that support mondrian
*/
@SuppressWarnings("deprecation")
public void testMDX_VFS_zipped_Schema() {
startTest();
// StandaloneSession session = new StandaloneSession(Messages.getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
// SolutionRepositoryVfs.setSolutionRepository( PentahoSystem.getSolutionRepository( session ) );
IPentahoSession session = new StandaloneSession("Admin");
// $NON-NLS-1$ //$NON-NLS-2$
OutputStream outputStream = this.getOutputStream("ConnectionTest.testSQLConnection", ".csv");
File file = // $NON-NLS-1$
new File(PentahoSystem.getApplicationContext().getSolutionPath("test/datasources/SampleDataSchema.zip"));
// $NON-NLS-1$ //$NON-NLS-2$
String catalog = "zip:" + file.toURI().toString() + "!/SampleData.mondrian.xml";
// $NON-NLS-1$
catalog = "solution:/test/datasources/SampleData.mondrian.xml;vfs=true";
IPentahoConnection connection = PentahoConnectionFactory.getConnection(IPentahoConnection.MDX_DATASOURCE, "jdbc:hsqldb:hsql://localhost:9001/sampledata; Catalog=" + catalog, "mondrian", "sa", "", session, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
null);
String query = // $NON-NLS-1$
"select {[Measures].[Actual], [Measures].[Budget]} on rows, {[Region].[All Regions]} ON columns from [Quadrant Analysis] WHERE ([Positions].[All Positions])";
try {
IPentahoResultSet results = connection.executeQuery(query);
Object[][] columnHeaders = results.getMetaData().getColumnHeaders();
for (int row = columnHeaders.length - 1; row >= 0; row--) {
for (int col = 0; col < columnHeaders[row].length; col++) {
// $NON-NLS-1$
outputStream.write((columnHeaders[row][col] + "\t").getBytes());
}
outputStream.write('\n');
}
Object[][] rowHeaders = results.getMetaData().getRowHeaders();
int rowIdx = 0;
Object[] row = results.next();
while (row != null) {
for (int colIdx = rowHeaders[rowIdx].length - 1; colIdx >= 0; colIdx--) {
// $NON-NLS-1$
outputStream.write((rowHeaders[rowIdx][colIdx].toString() + "\t").getBytes());
}
for (int colIdx = 0; colIdx < row.length; colIdx++) {
// $NON-NLS-1$
outputStream.write((row[colIdx] + "\t").getBytes());
}
outputStream.write('\n');
row = results.next();
rowIdx++;
}
results.close();
} catch (Exception e) {
e.printStackTrace();
}
connection.close();
finishTest();
}
use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class ConnectionIT method testSQLConnectionWithAllInfo.
public void testSQLConnectionWithAllInfo() {
startTest();
IPentahoSession session = new StandaloneSession("Admin");
// $NON-NLS-1$ //$NON-NLS-2$
OutputStream outputStream = this.getOutputStream("ConnectionTest.testConnectionWithPropertyName", ".csv");
File file = // $NON-NLS-1$
new File(PentahoSystem.getApplicationContext().getSolutionPath("test/datasources/SampleData.mondrian.xml"));
IPentahoConnection connection = PentahoConnectionFactory.getConnection(IPentahoConnection.MDX_DATASOURCE, "jdbc:hsqldb:hsql://localhost:9001/sampledata; Catalog=" + file.toURI().toString(), "mondrian", "sa", "", session, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
this);
try {
// $NON-NLS-1$
IPentahoResultSet results = connection.executeQuery("select * from DEPARTMENT_MANAGERS");
Object[][] columnHeaders = results.getMetaData().getColumnHeaders();
for (int row = 0; row < columnHeaders.length; row++) {
for (int col = 0; col < columnHeaders[0].length; col++) {
outputStream.write(columnHeaders[row][col].toString().getBytes());
// $NON-NLS-1$
outputStream.write(",".getBytes());
}
// $NON-NLS-1$
outputStream.write("\n".getBytes());
}
Object[] row = results.next();
while (row != null) {
for (int i = 0; i < row.length; i++) {
outputStream.write(row[i].toString().getBytes());
// $NON-NLS-1$
outputStream.write(",".getBytes());
}
// $NON-NLS-1$
outputStream.write("\n".getBytes());
row = results.next();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
connection.close();
finishTest();
}
use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class LocalizationServletIT method init.
@BeforeClass
public static void init() throws PlatformInitializationException {
StandaloneSession session = new StandaloneSession();
microPlatform = new MicroPlatform(TestResourceLocation.TEST_RESOURCES + "/web-servlet-solution");
microPlatform.define(ISolutionEngine.class, SolutionEngine.class);
microPlatform.define(IServiceManager.class, DefaultServiceManager.class, IPentahoDefinableObjectFactory.Scope.GLOBAL);
microPlatform.define(IPluginResourceLoader.class, PluginResourceLoader.class);
microPlatform.define(IPluginProvider.class, SystemPathXmlPluginProvider.class);
microPlatform.define(IPluginManager.class, DefaultPluginManager.class, IPentahoDefinableObjectFactory.Scope.GLOBAL);
PentahoSystem.setSystemSettingsService(new PathBasedSystemSettings());
PentahoSessionHolder.setSession(session);
IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class);
microPlatform.define(IPluginProvider.class, TestPluginProvider.class);
microPlatform.start();
pluginManager.reload(session);
}
Aggregations