Example usage for org.apache.commons.collections MultiMap size

List of usage examples for org.apache.commons.collections MultiMap size

Introduction

In this page you can find the example usage for org.apache.commons.collections MultiMap size.

Prototype

int size();

Source Link

Document

Gets the number of keys in this map.

Usage

From source file:fr.in2p3.cc.storage.treqs.persistence.db2.DB2ConfigurationDAOTest.java

/**
 * Gets 0 allocations.//from   ww w .j  a  v  a  2s. c  o m
 *
 * @throws TReqSException
 *             Never.
 */
@Test
public void testGetResourceAllocation01() throws TReqSException {
    DB2TestBroker.getInstance().connect();

    final MultiMap map = new DB2ConfigurationDAO().getResourceAllocation();

    final int actual = map.size();

    final int expected = 0;

    Assert.assertEquals(expected, actual);
    DB2TestBroker.getInstance().disconnect();
}

From source file:fr.in2p3.cc.storage.treqs.persistence.mysql.MySQLConfigurationDAOTest.java

/**
 * Gets 0 allocations.//from ww w. j a v a 2s.  c  om
 *
 * @throws TReqSException
 *             Never.
 */
@Test
public void testGetResourceAllocation01() throws TReqSException {
    MySQLBroker.getInstance().connect();

    final MultiMap map = new MySQLConfigurationDAO().getResourceAllocation();

    final int actual = map.size();

    final int expected = 0;

    Assert.assertEquals(expected, actual);
    MySQLBroker.getInstance().disconnect();
}

From source file:fr.in2p3.cc.storage.treqs.persistence.db2.DB2ConfigurationDAOTest.java

/**
 * Gets 1 allocation./*  ww w  .  j  av a 2s  .  c om*/
 *
 * @throws TReqSException
 *             Never.
 */
@Test
public void testGetResourceAllocation02() throws TReqSException {
    DB2TestBroker.getInstance().connect();

    String query = "INSERT INTO " + DB2Statements.MEDIATYPES + " VALUES (2, 'T10K-B', 7, '/TAPB')";
    DB2TestBroker.getInstance().executeModification(query);

    query = "INSERT INTO " + DB2Statements.ALLOCATIONS + " VALUES (2, 'user1', 0.5)";
    DB2TestBroker.getInstance().executeModification(query);

    final MultiMap map = new DB2ConfigurationDAO().getResourceAllocation();

    final int actual = map.size();

    final int expected = 1;

    Assert.assertEquals(expected, actual);
    DB2TestBroker.getInstance().disconnect();
}

From source file:fr.in2p3.cc.storage.treqs.persistence.mysql.MySQLConfigurationDAOTest.java

/**
 * Gets 1 allocation.//from www.j  a v  a  2s.  c  om
 *
 * @throws TReqSException
 *             Never.
 */
@Test
public void testGetResourceAllocation02() throws TReqSException {
    MySQLBroker.getInstance().connect();

    String query = "INSERT INTO " + MySQLStatements.MEDIATYPES + " VALUES (2, \"T10K-B\", 7, '/TAPB')";
    MySQLBroker.getInstance().executeModification(query);

    query = "INSERT INTO " + MySQLStatements.ALLOCATIONS + " VALUES (2, \"user1\", 0.5)";
    MySQLBroker.getInstance().executeModification(query);

    final MultiMap map = new MySQLConfigurationDAO().getResourceAllocation();

    final int actual = map.size();

    final int expected = 1;

    Assert.assertEquals(expected, actual);
    MySQLBroker.getInstance().disconnect();
}

From source file:fr.in2p3.cc.storage.treqs.persistence.db2.DB2ConfigurationDAOTest.java

/**
 * Gets two allocations./*from  w w w  . j a va  2  s. c o m*/
 *
 * @throws TReqSException
 *             Never.
 */
@Test
public void testGetResourceAllocation03() throws TReqSException {
    DB2TestBroker.getInstance().connect();

    String query = "INSERT INTO " + DB2Statements.MEDIATYPES + " VALUES (2, 'T10K-B', 7, '/TAPB')";
    DB2TestBroker.getInstance().executeModification(query);
    query = "INSERT INTO " + DB2Statements.MEDIATYPES + " VALUES (3, 'T10K-C', 8, '/TAPC')";
    DB2TestBroker.getInstance().executeModification(query);

    query = "INSERT INTO " + DB2Statements.ALLOCATIONS + " VALUES (3, 'user2', 0.6)";
    DB2TestBroker.getInstance().executeModification(query);
    query = "INSERT INTO " + DB2Statements.ALLOCATIONS + " VALUES (2, 'user3', 0.5)";
    DB2TestBroker.getInstance().executeModification(query);

    final MultiMap map = new DB2ConfigurationDAO().getResourceAllocation();

    final int actual = map.size();

    final int expected = 2;

    Assert.assertEquals(expected, actual);
    DB2TestBroker.getInstance().disconnect();
}

From source file:fr.in2p3.cc.storage.treqs.persistence.mysql.MySQLConfigurationDAOTest.java

/**
 * Gets two allocations./*from ww  w.  j  a  va  2 s  .c  om*/
 *
 * @throws TReqSException
 *             Never.
 */
@Test
public void testGetResourceAllocation03() throws TReqSException {
    MySQLBroker.getInstance().connect();

    String query = "INSERT INTO " + MySQLStatements.MEDIATYPES + " VALUES (2, \"T10K-B\", 7, '/TAPB')";
    MySQLBroker.getInstance().executeModification(query);
    query = "INSERT INTO " + MySQLStatements.MEDIATYPES + " VALUES (3, \"T10K-C\", 8, '/TAPC')";
    MySQLBroker.getInstance().executeModification(query);

    query = "INSERT INTO " + MySQLStatements.ALLOCATIONS + " VALUES (3, \"user2\", 0.6)";
    MySQLBroker.getInstance().executeModification(query);
    query = "INSERT INTO " + MySQLStatements.ALLOCATIONS + " VALUES (2, \"user3\", 0.5)";
    MySQLBroker.getInstance().executeModification(query);

    final MultiMap map = new MySQLConfigurationDAO().getResourceAllocation();

    final int actual = map.size();

    final int expected = 2;

    Assert.assertEquals(expected, actual);
    MySQLBroker.getInstance().disconnect();
}

From source file:fr.in2p3.cc.storage.treqs.control.dispatcher.Dispatcher.java

/**
 * Retrieves the requests from the data source.
 * <p>/*  w  w  w  .  j  a  v  a  2  s. c o m*/
 * This method has a default visibility just for testing purposes.
 * 
 * @throws TReqSException
 *             If there is problem retrieving the new requests.
 */
void retrieveNewRequests() throws TReqSException {
    LOGGER.trace("> retrieveNewRequest");

    // Get new requests
    final MultiMap newRequests = this.getNewRequests();
    if (newRequests != null) {

        // Loop through the new requests.
        if (newRequests.size() > 0) {
            LOGGER.info("Beginning MetaData fishing on HSM for {} files", newRequests.size());
        }
        this.process(newRequests);

        // Process more requests.
        if (this.moreRequests) {
            this.moreRequests = false;
            this.retrieveNewRequests();
        }
    }

    LOGGER.trace("< retrieveNewRequest");
}

From source file:fr.in2p3.cc.storage.treqs.persistence.mysql.dao.MySQLConfigurationDAO.java

@Override
public MultiMap getResourceAllocation() throws TReqSException {
    LOGGER.trace("> getResourceAllocation");

    // Allocations maps a media type to a pair (user,share)
    final MultiMap allocations = new MultiValueMap();

    final Object[] objects = MySQLBroker.getInstance().executeSelect(MySQLStatements.SQL_ALLOCATIONS_SELECT);

    // Store result
    final ResultSet result = (ResultSet) objects[1];
    try {// w  w w. j av  a2s  .c  o m
        while (result.next()) {
            int index = 1;
            final byte id = result.getByte(index++);
            final String userName = result.getString(index++);
            final float share = result.getFloat(index++);
            final PersistenceHelperResourceAllocation helper = new PersistenceHelperResourceAllocation(userName,
                    share);
            allocations.put(new Byte(id), helper);
            LOGGER.debug("Allocation on mediatype: '" + id + "', user: '" + userName + "', share: " + share);
        }
    } catch (final SQLException exception) {
        throw new MySQLExecuteException(exception);
    } finally {
        MySQLBroker.getInstance().terminateExecution(objects);
    }
    if (allocations.size() == 0) {
        // No entry in table, something wrong with configuration.
        LOGGER.warn("No media type allocations found. Please define them " + "in the database.");
    }

    LOGGER.trace("< getResourceAllocation");

    return allocations;
}

From source file:fr.in2p3.cc.storage.treqs.control.dispatcher.Dispatcher.java

/**
 * Processes the new requests and then put them in queues.
 * <p>//from  www .  ja  va  2 s  .  com
 * TODO v2.0 This should be multithreaded in order to ask several file
 * properties to the server simultaneously.
 * 
 * @param newRequests
 *            Map of new requests.
 * @throws TReqSException
 *             If there is a problem while processing the requests.
 */
@SuppressWarnings("unchecked")
private void process(final MultiMap newRequests) throws TReqSException {
    LOGGER.trace("> process");

    assert newRequests != null;

    short counter = this.maxFilesBeforeMessage;
    final Iterator<String> iterator = newRequests.keySet().iterator();
    while (iterator.hasNext()) {
        final String filename = iterator.next();
        final Iterator<FileRequest> iterator2 = ((Collection<FileRequest>) newRequests.get(filename))
                .iterator();
        while (iterator2.hasNext()) {
            final FileRequest fileRequest = iterator2.next();

            counter--;
            if (counter == 0) {
                LOGGER.info("{} files done", this.maxFilesBeforeMessage);
                counter = this.maxFilesBeforeMessage;
            }

            this.innerProcess(fileRequest);

        }
        if (newRequests.size() > 0) {
            LOGGER.info("Processing {} request(s)", newRequests.size());
        }
    }

    LOGGER.trace("< process");
}