use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class PluginManagerNotConfiguredIT method testPluginAdapterViaSystemListenerAPI.
@SuppressWarnings("cast")
public void testPluginAdapterViaSystemListenerAPI() throws Exception {
startTest();
// $NON-NLS-1$
IPentahoSession session = new StandaloneSession("test user");
PluginAdapter mgr = new PluginAdapter();
assertTrue(mgr instanceof IPentahoSystemListener);
IPentahoSystemListener listener = (IPentahoSystemListener) mgr;
assertFalse(listener.startup(session));
// this does not do anything but it shouldn't error
listener.shutdown();
finishTest();
}
use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class SystemPathPluginProviderIT method tesLoadtLifecycleListener.
@SuppressWarnings("deprecation")
@Test
public void tesLoadtLifecycleListener() throws PlatformPluginRegistrationException {
microPlatform.init();
PluginMessageLogger.clear();
List<IPlatformPlugin> plugins = provider.getPlugins(new StandaloneSession());
// first make sure Plugin 1 was loaded, otherwise our check for lifcycle class will never happen
assertTrue("plugin1 was not found", CollectionUtils.exists(plugins, new PluginNameMatcherPredicate("Plugin 1")));
for (IPlatformPlugin plugin : plugins) {
if (plugin.getId().equals("Plugin 1")) {
assertEquals("org.pentaho.test.platform.plugin.pluginmgr.FooInitializer", plugin.getLifecycleListenerClassname());
}
if (plugin.getId().equals("Plugin 2")) {
// no listener defined to for Plugin 2
assertNull(plugin.getLifecycleListenerClassname());
}
}
}
use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class SystemPathPluginProviderIT method testLoadLifeCycleListener.
@SuppressWarnings("deprecation")
@Test
public void testLoadLifeCycleListener() throws PlatformPluginRegistrationException {
microPlatform.init();
List<IPlatformPlugin> plugins = provider.getPlugins(new StandaloneSession());
IPlatformPlugin plugin = (IPlatformPlugin) CollectionUtils.find(plugins, new PluginNameMatcherPredicate("Plugin 1"));
assertNotNull("Plugin 1 should have been found", plugin);
assertEquals("org.pentaho.test.platform.plugin.pluginmgr.FooInitializer", plugin.getLifecycleListenerClassname());
}
use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class SystemPathPluginProviderIT method testLoadWebservices.
@SuppressWarnings("deprecation")
@Test
public void testLoadWebservices() throws PlatformPluginRegistrationException {
microPlatform.init();
List<IPlatformPlugin> plugins = provider.getPlugins(new StandaloneSession());
System.out.println(PluginMessageLogger.getAll());
IPlatformPlugin plugin = (IPlatformPlugin) CollectionUtils.find(plugins, new PluginNameMatcherPredicate("Plugin 1"));
assertNotNull("Plugin 1 should have been found", plugin);
Collection<PluginServiceDefinition> webservices = plugin.getServices();
Object wsobj = CollectionUtils.find(webservices, new Predicate() {
public boolean evaluate(Object object) {
PluginServiceDefinition ws = (PluginServiceDefinition) object;
boolean ret = ws.getTitle().equals("%TestWS1.TITLE%");
return ret;
}
});
assertNotNull("Webservice \"%TestWS1.TITLE%\" should have been loaded", wsobj);
PluginServiceDefinition wsDfn = (PluginServiceDefinition) wsobj;
assertEquals("org.pentaho.test.platform.engine.core.EchoServiceBean", wsDfn.getServiceClass());
assertEquals("xml", wsDfn.getTypes()[0]);
assertEquals("gwt", wsDfn.getTypes()[1]);
assertEquals("A test webservice", wsDfn.getDescription());
assertEquals(1, wsDfn.getExtraClasses().size());
assertEquals("java.lang.String", wsDfn.getExtraClasses().iterator().next());
}
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.
}
Aggregations