use of com.sun.jmx.examples.scandir.config.DirectoryScannerConfig in project jdk8u_jdk by JetBrains.
the class ScanDirConfigTest method testGetXmlConfigString.
/**
* Test of saveTo method, of class com.sun.jmx.examples.scandir.ScanProfile.
*/
/*
public void testSaveTo() throws Exception {
System.out.println("saveTo");
String filename = "";
ScanDirConfig instance = null;
instance.saveTo(filename);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of getXmlConfigString method, of class com.sun.jmx.examples.scandir.ScanDirConfig.
*/
public void testGetXmlConfigString() throws Exception {
System.out.println("getXmlConfigString");
try {
final File file = File.createTempFile("testconf", ".xml");
final ScanDirConfig instance = new ScanDirConfig(file.getAbsolutePath());
final ScanManagerConfig bean = new ScanManagerConfig("testGetXmlConfigString");
final DirectoryScannerConfig dir = new DirectoryScannerConfig("tmp");
dir.setRootDirectory(file.getParent());
bean.putScan(dir);
instance.setConfiguration(bean);
System.out.println("Expected: " + XmlConfigUtils.toString(bean));
System.out.println("Received: " + instance.getConfiguration().toString());
assertEquals(XmlConfigUtils.toString(bean), instance.getConfiguration().toString());
} catch (Exception x) {
x.printStackTrace();
throw x;
}
}
use of com.sun.jmx.examples.scandir.config.DirectoryScannerConfig in project jdk8u_jdk by JetBrains.
the class ScanDirConfigTest method testLoad.
/**
* Test of load method, of class com.sun.jmx.examples.scandir.ScanDirConfig.
*/
public void testLoad() throws Exception {
System.out.println("load");
final File file = File.createTempFile("testconf", ".xml");
final ScanDirConfig instance = new ScanDirConfig(file.getAbsolutePath());
final ScanManagerConfig bean = new ScanManagerConfig("testLoad");
final DirectoryScannerConfig dir = new DirectoryScannerConfig("tmp");
dir.setRootDirectory(file.getParent());
bean.putScan(dir);
XmlConfigUtils.write(bean, new FileOutputStream(file), false);
instance.load();
assertEquals(bean, instance.getConfiguration());
bean.removeScan(dir.getName());
XmlConfigUtils.write(bean, new FileOutputStream(file), false);
assertNotSame(bean, instance.getConfiguration());
instance.load();
assertEquals(bean, instance.getConfiguration());
}
use of com.sun.jmx.examples.scandir.config.DirectoryScannerConfig in project jdk8u_jdk by JetBrains.
the class ScanDirConfigTest method testSave.
/**
* Test of save method, of class com.sun.jmx.examples.scandir.ScanDirConfig.
*/
public void testSave() throws Exception {
System.out.println("save");
final File file = File.createTempFile("testconf", ".xml");
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
final ScanManagerMXBean manager = ScanManager.register(mbs);
try {
final ScanDirConfigMXBean instance = manager.createOtherConfigurationMBean("testSave", file.getAbsolutePath());
assertTrue(mbs.isRegistered(ScanManager.makeScanDirConfigName("testSave")));
final ScanManagerConfig bean = new ScanManagerConfig("testSave");
final DirectoryScannerConfig dir = new DirectoryScannerConfig("tmp");
dir.setRootDirectory(file.getParent());
bean.putScan(dir);
instance.setConfiguration(bean);
instance.save();
final ScanManagerConfig loaded = new XmlConfigUtils(file.getAbsolutePath()).readFromFile();
assertEquals(instance.getConfiguration(), loaded);
assertEquals(bean, loaded);
instance.getConfiguration().removeScan("tmp");
instance.save();
assertNotSame(loaded, instance.getConfiguration());
final ScanManagerConfig loaded2 = new XmlConfigUtils(file.getAbsolutePath()).readFromFile();
assertEquals(instance.getConfiguration(), loaded2);
} finally {
manager.close();
mbs.unregisterMBean(ScanManager.SCAN_MANAGER_NAME);
}
final ObjectName all = new ObjectName(ScanManager.SCAN_MANAGER_NAME.getDomain() + ":*");
assertEquals(0, mbs.queryNames(all, null).size());
}
use of com.sun.jmx.examples.scandir.config.DirectoryScannerConfig in project jdk8u_jdk by JetBrains.
the class DirectoryScannerTest method testScan.
/**
* Test of scan method, of class com.sun.jmx.examples.scandir.DirectoryScanner.
*/
public void testScan() throws Exception {
System.out.println("scan");
final ScanManagerMXBean manager = ScanManager.register();
try {
final String tmpdir = System.getProperty("java.io.tmpdir");
final ScanDirConfigMXBean config = manager.getConfigurationMBean();
final DirectoryScannerConfig bean = config.addDirectoryScanner("test1", tmpdir, ".*", 0, 0);
config.addDirectoryScanner("test2", tmpdir, ".*", 0, 0);
config.addDirectoryScanner("test3", tmpdir, ".*", 0, 0);
manager.applyConfiguration(true);
final DirectoryScannerMXBean proxy = manager.getDirectoryScanners().get("test1");
final Call op = new Call() {
public void call() throws Exception {
final BlockingQueue<Notification> queue = new LinkedBlockingQueue<Notification>();
final NotificationListener listener = new NotificationListener() {
public void handleNotification(Notification notification, Object handback) {
try {
queue.put(notification);
} catch (Exception e) {
e.printStackTrace();
}
}
};
manager.start();
while (true) {
final Notification n = queue.poll(10, TimeUnit.SECONDS);
if (n == null)
break;
final AttributeChangeNotification at = (AttributeChangeNotification) n;
if (RUNNING == ScanState.valueOf((String) at.getNewValue()))
break;
else {
System.err.println("New state: " + (String) at.getNewValue() + " isn't " + RUNNING);
}
}
assertContained(EnumSet.of(SCHEDULED, RUNNING, COMPLETED), proxy.getState());
}
public void cancel() throws Exception {
manager.stop();
}
};
doTestOperation(proxy, op, EnumSet.of(RUNNING, SCHEDULED, COMPLETED), "scan");
} catch (Exception x) {
x.printStackTrace();
throw x;
} finally {
try {
manager.stop();
} catch (Exception x) {
System.err.println("Failed to stop: " + x);
}
try {
ManagementFactory.getPlatformMBeanServer().unregisterMBean(ScanManager.SCAN_MANAGER_NAME);
} catch (Exception x) {
System.err.println("Failed to cleanup: " + x);
}
}
}
use of com.sun.jmx.examples.scandir.config.DirectoryScannerConfig in project jdk8u_jdk by JetBrains.
the class DirectoryScannerTest method testGetState.
/**
* Test of getState method, of class com.sun.jmx.examples.scandir.DirectoryScanner.
*/
public void testGetState() {
System.out.println("getState");
final DirectoryScannerConfig bean = new DirectoryScannerConfig("test");
bean.setRootDirectory(System.getProperty("java.io.tmpdir"));
final ResultLogManager log = new ResultLogManager();
DirectoryScanner instance = new DirectoryScanner(bean, log);
ScanState expResult = STOPPED;
ScanState result = instance.getState();
assertEquals(STOPPED, result);
instance.scan();
result = instance.getState();
assertEquals(COMPLETED, result);
}
Aggregations