|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | +package org.apache.cloudstack.framework.jobs; |
| 18 | + |
| 19 | +/* |
| 20 | + * This integration test requires real DB setup, it is not meant to run at per-build |
| 21 | + * basis, it can only be opened in developer's run |
| 22 | + * |
| 23 | + * |
| 24 | +
|
| 25 | +@RunWith(SpringJUnit4ClassRunner.class) |
| 26 | +@ContextConfiguration(locations = "classpath:/AsyncJobManagerTestContext.xml") |
| 27 | +public class AsyncJobManagerTest extends TestCase { |
| 28 | + private static final Logger s_logger = |
| 29 | + Logger.getLogger(AsyncJobManagerTest.class); |
| 30 | +
|
| 31 | + @Inject |
| 32 | + AsyncJobManager _jobMgr; |
| 33 | +
|
| 34 | + @Inject |
| 35 | + AsyncJobTestDashboard _testDashboard; |
| 36 | +
|
| 37 | + @Override |
| 38 | + @Before |
| 39 | + public void setUp() throws Exception { |
| 40 | + try { |
| 41 | + ComponentContext.initComponentsLifeCycle(); |
| 42 | + } catch (Exception ex) { |
| 43 | + ex.printStackTrace(); |
| 44 | + s_logger.error(ex.getMessage()); |
| 45 | + } |
| 46 | + } |
| 47 | +
|
| 48 | + @Override |
| 49 | + @After |
| 50 | + public void tearDown() throws Exception { |
| 51 | + } |
| 52 | +
|
| 53 | + public void testWaitBehave() { |
| 54 | +
|
| 55 | + final Object me = this; |
| 56 | + new Thread(new Runnable() { |
| 57 | +
|
| 58 | + @Override |
| 59 | + public void run() { |
| 60 | + s_logger.info("Sleeping..."); |
| 61 | + try { |
| 62 | + Thread.sleep(3000); |
| 63 | + } catch (InterruptedException e) { |
| 64 | + } |
| 65 | +
|
| 66 | + s_logger.info("wakeup"); |
| 67 | + synchronized (me) { |
| 68 | + me.notifyAll(); |
| 69 | + } |
| 70 | + } |
| 71 | +
|
| 72 | + }).start(); |
| 73 | +
|
| 74 | + s_logger.info("First wait"); |
| 75 | + synchronized (me) { |
| 76 | + try { |
| 77 | + wait(5000); |
| 78 | + } catch (InterruptedException e) { |
| 79 | + // TODO Auto-generated catch block |
| 80 | + e.printStackTrace(); |
| 81 | + } |
| 82 | + } |
| 83 | + s_logger.info("First wait done"); |
| 84 | +
|
| 85 | + s_logger.info("Second wait"); |
| 86 | + synchronized (me) { |
| 87 | + try { |
| 88 | + wait(5000); |
| 89 | + } catch (InterruptedException e) { |
| 90 | + // TODO Auto-generated catch block |
| 91 | + e.printStackTrace(); |
| 92 | + } |
| 93 | + } |
| 94 | + s_logger.info("Second wait done"); |
| 95 | + } |
| 96 | +
|
| 97 | + @Test |
| 98 | + public void test() { |
| 99 | + final int TOTAL_JOBS_PER_QUEUE = 5; |
| 100 | + final int TOTAL_QUEUES = 100; |
| 101 | +
|
| 102 | + for (int i = 0; i < TOTAL_QUEUES; i++) { |
| 103 | + for (int j = 0; j < TOTAL_JOBS_PER_QUEUE; j++) { |
| 104 | + AsyncJobVO job = new AsyncJobVO(); |
| 105 | + job.setCmd("TestCmd"); |
| 106 | + job.setDispatcher("TestJobDispatcher"); |
| 107 | + job.setCmdInfo("TestCmd info"); |
| 108 | +
|
| 109 | + _jobMgr.submitAsyncJob(job, "fakequeue", i); |
| 110 | +
|
| 111 | + s_logger.info("Job submitted. job " + job.getId() + ", queue: " + i); |
| 112 | + } |
| 113 | + } |
| 114 | +
|
| 115 | + while (true) { |
| 116 | + if (_testDashboard.getCompletedJobCount() == TOTAL_JOBS_PER_QUEUE * TOTAL_QUEUES) |
| 117 | + break; |
| 118 | +
|
| 119 | + try { |
| 120 | + Thread.sleep(1000); |
| 121 | + } catch (InterruptedException e) { |
| 122 | + } |
| 123 | + } |
| 124 | +
|
| 125 | + s_logger.info("Test done with " + _testDashboard.getCompletedJobCount() + " job executed"); |
| 126 | + } |
| 127 | +} |
| 128 | +
|
| 129 | +*/ |
0 commit comments