Search in sources :

Example 1 with ScanManagerConfig

use of com.sun.jmx.examples.scandir.config.ScanManagerConfig in project jdk8u_jdk by JetBrains.

the class ScanDirConfigTest method testAddDirectoryScanner.

/**
     * Test of addDirectoryScanner method, of class
     * com.sun.jmx.examples.scandir.ScanDirConfig.
     */
public void testAddDirectoryScanner() throws IOException {
    System.out.println("addDirectoryScanner");
    System.out.println("save");
    final File file = File.createTempFile("testconf", ".xml");
    final ScanDirConfig instance = new ScanDirConfig(file.getAbsolutePath());
    final ScanManagerConfig bean = new ScanManagerConfig("testSave");
    final DirectoryScannerConfig dir = new DirectoryScannerConfig("tmp");
    dir.setRootDirectory(file.getParent());
    FileMatch filter = new FileMatch();
    filter.setFilePattern(".*");
    dir.setIncludeFiles(new FileMatch[] { filter });
    instance.setConfiguration(bean);
    instance.addDirectoryScanner(dir.getName(), dir.getRootDirectory(), filter.getFilePattern(), filter.getSizeExceedsMaxBytes(), 0);
    instance.save();
    final ScanManagerConfig loaded = new XmlConfigUtils(file.getAbsolutePath()).readFromFile();
    assertNotNull(loaded.getScan(dir.getName()));
    assertEquals(dir, loaded.getScan(dir.getName()));
    assertEquals(instance.getConfiguration(), loaded);
    assertEquals(instance.getConfiguration().getScan(dir.getName()), dir);
}
Also used : ScanManagerConfig(com.sun.jmx.examples.scandir.config.ScanManagerConfig) DirectoryScannerConfig(com.sun.jmx.examples.scandir.config.DirectoryScannerConfig) XmlConfigUtils(com.sun.jmx.examples.scandir.config.XmlConfigUtils) File(java.io.File) FileMatch(com.sun.jmx.examples.scandir.config.FileMatch)

Example 2 with ScanManagerConfig

use of com.sun.jmx.examples.scandir.config.ScanManagerConfig in project jdk8u_jdk by JetBrains.

the class ScanDirConfigTest method testAddNotificationListener.

/**
     * Test of addNotificationListener method, of class
     * com.sun.jmx.examples.scandir.ScanDirConfig.
     */
public void testAddNotificationListener() throws Exception {
    System.out.println("addNotificationListener");
    final File file = File.createTempFile("testconf", ".xml");
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    final ScanManagerMXBean manager = ScanManager.register(mbs);
    try {
        final ScanDirConfigMXBean instance = TestUtils.makeNotificationEmitter(manager.createOtherConfigurationMBean("testSave", file.getAbsolutePath()), ScanDirConfigMXBean.class);
        assertTrue(mbs.isRegistered(ScanManager.makeScanDirConfigName("testSave")));
        DirectoryScannerConfig dir = instance.addDirectoryScanner("tmp", file.getParent(), ".*", 0, 0);
        final BlockingQueue<Notification> queue = new LinkedBlockingQueue<Notification>();
        final NotificationListener listener = new NotificationListener() {

            public void handleNotification(Notification notification, Object handback) {
                queue.add(notification);
            }
        };
        NotificationFilter filter = null;
        Object handback = null;
        ((NotificationEmitter) instance).addNotificationListener(listener, filter, handback);
        instance.save();
        final ScanManagerConfig loaded = new XmlConfigUtils(file.getAbsolutePath()).readFromFile();
        assertEquals(instance.getConfiguration(), loaded);
        final ScanManagerConfig newConfig = instance.getConfiguration();
        newConfig.removeScan("tmp");
        instance.setConfiguration(newConfig);
        instance.save();
        assertNotSame(loaded, instance.getConfiguration());
        final ScanManagerConfig loaded2 = new XmlConfigUtils(file.getAbsolutePath()).readFromFile();
        assertEquals(instance.getConfiguration(), loaded2);
        instance.load();
        for (int i = 0; i < 4; i++) {
            final Notification n = queue.poll(3, TimeUnit.SECONDS);
            assertNotNull(n);
            assertEquals(TestUtils.getObjectName(instance), n.getSource());
            switch(i) {
                case 0:
                case 2:
                    assertEquals(ScanDirConfig.NOTIFICATION_SAVED, n.getType());
                    break;
                case 1:
                    assertEquals(ScanDirConfig.NOTIFICATION_MODIFIED, n.getType());
                    break;
                case 3:
                    assertEquals(ScanDirConfig.NOTIFICATION_LOADED, n.getType());
                    break;
                default:
                    break;
            }
        }
    } 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());
}
Also used : LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) ScanManagerConfig(com.sun.jmx.examples.scandir.config.ScanManagerConfig) DirectoryScannerConfig(com.sun.jmx.examples.scandir.config.DirectoryScannerConfig) XmlConfigUtils(com.sun.jmx.examples.scandir.config.XmlConfigUtils) File(java.io.File)

Example 3 with ScanManagerConfig

use of com.sun.jmx.examples.scandir.config.ScanManagerConfig 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;
    }
}
Also used : ScanManagerConfig(com.sun.jmx.examples.scandir.config.ScanManagerConfig) DirectoryScannerConfig(com.sun.jmx.examples.scandir.config.DirectoryScannerConfig) File(java.io.File) IOException(java.io.IOException)

Example 4 with ScanManagerConfig

use of com.sun.jmx.examples.scandir.config.ScanManagerConfig in project jdk8u_jdk by JetBrains.

the class ScanManager method applyCurrentResultLogConfig.

// See ScanManagerMXBean
public void applyCurrentResultLogConfig(boolean toMemory) throws IOException, JMException {
    final ScanManagerConfig bean = config.getConfiguration();
    bean.setInitialResultLogConfig(log.getConfig());
    config.setConfiguration(bean);
    if (toMemory == false)
        config.save();
}
Also used : ScanManagerConfig(com.sun.jmx.examples.scandir.config.ScanManagerConfig)

Example 5 with ScanManagerConfig

use of com.sun.jmx.examples.scandir.config.ScanManagerConfig 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());
}
Also used : ScanManagerConfig(com.sun.jmx.examples.scandir.config.ScanManagerConfig) DirectoryScannerConfig(com.sun.jmx.examples.scandir.config.DirectoryScannerConfig) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

ScanManagerConfig (com.sun.jmx.examples.scandir.config.ScanManagerConfig)6 DirectoryScannerConfig (com.sun.jmx.examples.scandir.config.DirectoryScannerConfig)5 File (java.io.File)5 XmlConfigUtils (com.sun.jmx.examples.scandir.config.XmlConfigUtils)3 FileMatch (com.sun.jmx.examples.scandir.config.FileMatch)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1