Search in sources :

Example 1 with HostDao

use of com.cloud.host.dao.HostDao in project CloudStack-archive by CloudStack-extras.

the class TestAsyncJobManager method sequence.

public void sequence() {
    final HostDao hostDao = new HostDaoImpl();
    long seq = hostDao.getNextSequence(1);
    s_logger.info("******* seq : " + seq + " ********");
    HashMap<Long, Long> hashMap = new HashMap<Long, Long>();
    final Map<Long, Long> map = Collections.synchronizedMap(hashMap);
    s_count = 0;
    // test one million times
    final long maxCount = 1000000;
    Thread t1 = new Thread(new Runnable() {

        public void run() {
            while (s_count < maxCount) {
                s_count++;
                long seq = hostDao.getNextSequence(1);
                Assert.assertTrue(map.put(seq, seq) == null);
            }
        }
    });
    Thread t2 = new Thread(new Runnable() {

        public void run() {
            while (s_count < maxCount) {
                s_count++;
                long seq = hostDao.getNextSequence(1);
                Assert.assertTrue(map.put(seq, seq) == null);
            }
        }
    });
    t1.start();
    t2.start();
    try {
        t1.join();
        t2.join();
    } catch (InterruptedException e) {
    }
}
Also used : HashMap(java.util.HashMap) HostDaoImpl(com.cloud.host.dao.HostDaoImpl) HostDao(com.cloud.host.dao.HostDao)

Example 2 with HostDao

use of com.cloud.host.dao.HostDao in project CloudStack-archive by CloudStack-extras.

the class TestAsyncJobManager method tstLocking.

public void tstLocking() {
    int testThreads = 20;
    Thread[] threads = new Thread[testThreads];
    for (int i = 0; i < testThreads; i++) {
        final int current = i;
        threads[i] = new Thread(new Runnable() {

            public void run() {
                final HostDao hostDao = new HostDaoImpl();
                while (true) {
                    Transaction txn = Transaction.currentTxn();
                    try {
                        HostVO host = hostDao.acquireInLockTable(getRandomLockId(), 10);
                        if (host != null) {
                            s_logger.info("Thread " + (current + 1) + " acquired lock");
                            try {
                                Thread.sleep(getRandomMilliseconds(1000, 5000));
                            } catch (InterruptedException e) {
                            }
                            s_logger.info("Thread " + (current + 1) + " released lock");
                            hostDao.releaseFromLockTable(host.getId());
                            try {
                                Thread.sleep(getRandomMilliseconds(1000, 5000));
                            } catch (InterruptedException e) {
                            }
                        } else {
                            s_logger.info("Thread " + (current + 1) + " is not able to acquire lock");
                        }
                    } finally {
                        txn.close();
                    }
                }
            }
        });
        threads[i].start();
    }
    try {
        for (int i = 0; i < testThreads; i++) threads[i].join();
    } catch (InterruptedException e) {
    }
}
Also used : Transaction(com.cloud.utils.db.Transaction) HostDaoImpl(com.cloud.host.dao.HostDaoImpl) HostDao(com.cloud.host.dao.HostDao) HostVO(com.cloud.host.HostVO)

Example 3 with HostDao

use of com.cloud.host.dao.HostDao in project cloudstack by apache.

the class AgentManagerImplTest method setUp.

@Before
public void setUp() throws Exception {
    host = new HostVO("some-Uuid");
    host.setDataCenterId(1L);
    cmds = new StartupCommand[] { new StartupRoutingCommand() };
    attache = new ConnectedAgentAttache(null, 1L, "kvm-attache", null, false);
    hostDao = Mockito.mock(HostDao.class);
    storagePoolMonitor = Mockito.mock(Listener.class);
    mgr._hostDao = hostDao;
    mgr._hostMonitors = new ArrayList<>();
    mgr._hostMonitors.add(new Pair<>(0, storagePoolMonitor));
}
Also used : Listener(com.cloud.agent.Listener) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) HostVO(com.cloud.host.HostVO) HostDao(com.cloud.host.dao.HostDao) Before(org.junit.Before)

Example 4 with HostDao

use of com.cloud.host.dao.HostDao in project cloudstack by apache.

the class ChildTestConfiguration method hostDao.

@Override
@Bean
public HostDao hostDao() {
    HostDao dao = super.hostDao();
    HostDao nDao = Mockito.spy(dao);
    return nDao;
}
Also used : HostDao(com.cloud.host.dao.HostDao) Bean(org.springframework.context.annotation.Bean)

Aggregations

HostDao (com.cloud.host.dao.HostDao)4 HostVO (com.cloud.host.HostVO)2 HostDaoImpl (com.cloud.host.dao.HostDaoImpl)2 Listener (com.cloud.agent.Listener)1 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)1 Transaction (com.cloud.utils.db.Transaction)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 Bean (org.springframework.context.annotation.Bean)1