Search in sources :

Example 1 with TimestampedStringQueue

use of alma.acs.util.stringqueue.TimestampedStringQueue in project ACS by ACS-Community.

the class StringQueueNotification method testFilesCreation.

/**
	 * Check if a new file is created when expected by checking the size of 
	 * strings in cache against the max length of the file handler.
	 * It also implicitly test it the queue works with a generic time-stamped string instead of a log.
	 * <P>
	 * For this test the dates are not important but only the total
	 * length of the strings pushed in the queue. 
	 * In fact, now we push generic time-stamped strings instead of logs.
	 * <P>
	 * testFilesCreation pushes a set of generic string each of each 
	 * has a unique integer ID. When the size of the pushed string
	 * is greater then the max length of the file, we expect the cache to create a new file.
	 * The test will ten also get out all the strings and check for their 
	 * integrity, checking the value of their IDs.
	 * 
	 * @throws Exception
	 */
public void testFilesCreation() throws Exception {
    System.out.println("testFilesCreation started");
    String strHdr = "A generic timestamped string to push in queue " + "TIMESTAMP=\"";
    String strFooter = "\" End of generic String ";
    assertEquals("A newly created cache should have 0 files!", stringQueue.getActiveFilesSize(), 0);
    // The size of the strings pushed in the queue
    long size = 0;
    // The unique ID of each string (the first string in queue has ID=1)
    int ID = 0;
    // We instantiate another queue for the test because we are not
    // interested in checking the timestamps (TestFileHandler#fileProcessed would return
    // error without setting the oldest and newest timestamp and with another queue
    // this test is simpler)
    TimestampedStringQueue queue = new TimestampedStringQueue(cacheFileSize, "TIMESTAMP=\"");
    while (size <= cacheFileSize) {
        ID++;
        String now = IsoDateFormat.formatDate(new Date(System.currentTimeMillis()));
        String strToPush = strHdr + now + strFooter + ID;
        queue.push(strToPush);
        size += strToPush.length();
        assertEquals("The size of the cache differs from the number of pushed strings", ID, queue.size());
    }
    // Now there should be 2 files in the cache
    assertEquals("Wrong number of files in queue", 2, queue.getActiveFilesSize());
    // Get the strings out and checks their IDs
    for (int t = 1; t <= ID; t++) {
        String str = queue.pop();
        assertNotNull(str);
        assertEquals("The size of the cache differs from expected", ID - t, queue.size());
        // Check the integrity of the string
        assertTrue(str.startsWith(strHdr));
        assertTrue("Str red from queue is [" + str + "] but we expect it to have iD=" + t, str.endsWith(strFooter + t));
    }
    // The queue should be empty here
    assertEquals("The queue should be empty!", 0, queue.size());
    // And should have no files
    assertEquals("The queue should have 0 files!", 1, queue.getActiveFilesSize());
    queue.close(true);
    System.out.println("testFilesCreation done");
}
Also used : TimestampedStringQueue(alma.acs.util.stringqueue.TimestampedStringQueue) Date(java.util.Date)

Example 2 with TimestampedStringQueue

use of alma.acs.util.stringqueue.TimestampedStringQueue in project ACS by ACS-Community.

the class StringQueueNotification method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    checkNotification = true;
    testFileHandler = new TestFileHandler(cacheFileSize);
    assertNotNull(testFileHandler);
    assertEquals("Size max size of cache differs from the passed one", testFileHandler.maxFilesSize, cacheFileSize);
    stringQueue = new TimestampedStringQueue(testFileHandler, "TIMESTAMP=\"");
    assertNotNull(stringQueue);
    stringQueue.start();
    System.out.println("Queue started: now the test begins");
}
Also used : TimestampedStringQueue(alma.acs.util.stringqueue.TimestampedStringQueue)

Example 3 with TimestampedStringQueue

use of alma.acs.util.stringqueue.TimestampedStringQueue in project ACS by ACS-Community.

the class DefaultFileHandlerTest method testDefaultXmlQueueFileHandlerImpl.

/**
	 * Push strings in cache to generate 2 files.
	 * <P>
	 * The checks are done by {@link MyXmlFileHandler}
	 * 
	 * @throws Exception
	 */
public void testDefaultXmlQueueFileHandlerImpl() throws Exception {
    // We want the cache to generate 2 files
    Vector<String> strToPush = generateStrings(MAX_FILE_SIZE + 2048);
    MyXmlFileHandler fHandler = new MyXmlFileHandler(MAX_FILE_SIZE, xmlTag);
    TimestampedStringQueue queue = new TimestampedStringQueue(fHandler, timestampIdentifier);
    queue.start();
    int t = 0;
    while (queue.getActiveFilesSize() < 2) {
        queue.push(strToPush.get(t++));
        assertEquals("Inconsistent number of files in cache", fHandler.createdFiles, queue.getActiveFilesSize());
    }
    queue.close(true);
}
Also used : TimestampedStringQueue(alma.acs.util.stringqueue.TimestampedStringQueue)

Example 4 with TimestampedStringQueue

use of alma.acs.util.stringqueue.TimestampedStringQueue in project ACS by ACS-Community.

the class XmlFileStoreAlarmImpl method initialize.

/**
	 * Life cycle
	 * @see alma.acs.component.ComponentLifecycle#initialize()
	 */
@Override
public void initialize(ContainerServices containerServices) throws ComponentLifecycleException {
    super.initialize(containerServices);
    cs = containerServices;
    m_logger = cs.getLogger();
    // Prepare the queue
    String folderPath = System.getProperty(XmlFileStoreAlarmImpl.LOGDIR_PROPNAME, XmlFileStoreAlarmImpl.DEFAULLOGDIR);
    File f = new File(folderPath);
    if (!f.exists()) {
        f.mkdirs();
    }
    int fileMax = Integer.getInteger(XmlFileStoreAlarmImpl.MAXNUMBEROFFILES_PROPNAME, XmlFileStoreAlarmImpl.DEFAULTMAXNUMBEROFFILES);
    int fileSizeLimit = Integer.getInteger(XmlFileStoreAlarmImpl.MAXFILESIZE_PROPNAME, XmlFileStoreAlarmImpl.DEFAULTMAXFILESIZE);
    if (fileMax < 1 || fileSizeLimit < 100000) {
        StringBuilder str = new StringBuilder(XmlFileStoreAlarmImpl.MAXNUMBEROFFILES_PROPNAME);
        str.append(" must be greater then 1 and ");
        str.append(XmlFileStoreAlarmImpl.MAXFILESIZE_PROPNAME);
        str.append(" must be greater then 100000");
        throw new ComponentLifecycleException(str.toString());
    }
    StringBuilder str = new StringBuilder("Will save alarms files in : ");
    str.append(folderPath);
    str.append(" (max log file size: ");
    str.append(fileSizeLimit);
    str.append(", max # log files: ");
    str.append(fileMax);
    str.append(')');
    m_logger.info(str.toString());
    QueueFileHandler qFileHandler;
    try {
        qFileHandler = new QueueFileHandler(cs, folderPath, fileMax, fileSizeLimit, "alarmSources", "AlarmsLogger");
    } catch (Throwable t) {
        throw new ComponentLifecycleException("Could not create the queue file handler", t);
    }
    queue = new TimestampedStringQueue(qFileHandler, "<source-timestamp>");
    queue.start();
    // Connects to the alarm source NC
    try {
        alarmSourceClient = new SourceClient(cs);
        alarmSourceClient.connect();
    } catch (Throwable t) {
        throw new ComponentLifecycleException("Could not connect to alarm source NC", t);
    }
    alarmSourceClient.addAlarmListener(this);
}
Also used : QueueFileHandler(alma.acs.xmlfilestore.common.QueueFileHandler) TimestampedStringQueue(alma.acs.util.stringqueue.TimestampedStringQueue) ComponentLifecycleException(alma.acs.component.ComponentLifecycleException) SourceClient(alma.alarmsystem.clients.SourceClient) File(java.io.File)

Example 5 with TimestampedStringQueue

use of alma.acs.util.stringqueue.TimestampedStringQueue in project ACS by ACS-Community.

the class TimestampedStringQueueTest method setUp.

/* (non-Javadoc)
	 * @see junit.framework.TestCase#setUp()
	 */
@Override
protected void setUp() throws Exception {
    super.setUp();
    // Build the cache
    cache = new TimestampedStringQueue(CACHE_SIZE, "TIMESTAMP=\"");
    assertNotNull(cache);
    assertEquals(0, cache.getActiveFilesSize());
    assertEquals(0, cache.size());
}
Also used : TimestampedStringQueue(alma.acs.util.stringqueue.TimestampedStringQueue)

Aggregations

TimestampedStringQueue (alma.acs.util.stringqueue.TimestampedStringQueue)6 ComponentLifecycleException (alma.acs.component.ComponentLifecycleException)1 QueueFileHandler (alma.acs.xmlfilestore.common.QueueFileHandler)1 SourceClient (alma.alarmsystem.clients.SourceClient)1 File (java.io.File)1 Date (java.util.Date)1