awips2/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/WfoNcfBandwidthManagerIntTest.java
Dave Hladky 5fa53b22dc Issue #2992 Updated DD list of active registries
Change-Id: Iaef7dc76442d1e101cf9865a542a777afe1722ca

Former-commit-id: a14cb8c45f [formerly e2a4bb6755] [formerly c352643c79] [formerly a14cb8c45f [formerly e2a4bb6755] [formerly c352643c79] [formerly 3b00ae03cc [formerly c352643c79 [formerly a34955102d1316135c4151210daba0e5807ff6c9]]]]
Former-commit-id: 3b00ae03cc
Former-commit-id: 5fc17cf3b8 [formerly ea791b5ca5] [formerly 271120a82cffba35438f0b9830c3a47c736fcb73 [formerly bf42c8d740]]
Former-commit-id: 966b34bc10a6cb76f151b577b0acae7fb953d804 [formerly 5b11e45636]
Former-commit-id: a06db5a4e7
2014-04-30 17:38:28 -05:00

236 lines
8.7 KiB
Java

/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.edex.datadelivery.bandwidth;
import static org.hamcrest.Matchers.emptyCollectionOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.raytheon.uf.common.datadelivery.bandwidth.BandwidthRequest;
import com.raytheon.uf.common.datadelivery.bandwidth.BandwidthRequest.RequestType;
import com.raytheon.uf.common.datadelivery.registry.Network;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryConstants;
import com.raytheon.uf.common.serialization.comm.IRequestRouter;
import com.raytheon.uf.common.serialization.comm.IServerRequest;
import com.raytheon.uf.common.serialization.comm.RequestRouterTest;
import com.raytheon.uf.common.util.SpringFiles;
import com.raytheon.uf.common.util.registry.RegistryException;
import com.raytheon.uf.edex.datadelivery.bandwidth.WfoBandwidthManagerCreator.WfoBandwidthManager;
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation;
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthSubscription;
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao;
/**
* Test interactions between a {@link WfoBandwidthManager} and a
* {@link NcfBandwidthManager}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 27, 2013 1644 djohnson Initial creation
* Jul 10, 2013 2106 djohnson Dependency inject registry handlers.
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class WfoNcfBandwidthManagerIntTest extends
AbstractWfoBandwidthManagerIntTest {
private BandwidthManager ncfBandwidthManager;
private IBandwidthDao ncfBandwidthDao;
@Override
public void setUp() {
super.setUp();
// Set up the NCF bandwidth manager
ApplicationContext ncfBandwidthManagerCtx = new ClassPathXmlApplicationContext(
new String[] {
SpringFiles.UNIT_TEST_DB_BEANS_XML,
SpringFiles.MEMORY_DATADELIVERY_HANDLERS_XML,
SpringFiles.RETRIEVAL_DATADELIVERY_DAOS_XML,
SpringFiles.BANDWIDTH_DATADELIVERY_DAOS_XML,
SpringFiles.BANDWIDTH_DATADELIVERY_XML,
SpringFiles.BANDWIDTH_DATADELIVERY_NCF_XML,
SpringFiles.BANDWIDTH_DATADELIVERY_INTEGRATION_TEST_XML,
SpringFiles.BANDWIDTH_DATADELIVERY_INTEGRATION_TEST_NCF_XML });
ncfBandwidthManager = (BandwidthManager) ncfBandwidthManagerCtx
.getBean("bandwidthManager");
ncfBandwidthDao = (IBandwidthDao) ncfBandwidthManagerCtx
.getBean("bandwidthDao");
// Add the router to the NCF bandwidth manager
RequestRouterTest.clearRegistry();
try {
RequestRouterTest.register(
DataDeliveryConstants.NCF_BANDWIDTH_MANAGER_SERVICE,
new IRequestRouter() {
@Override
public Object route(IServerRequest request)
throws Exception {
return ncfBandwidthManager
.handleRequest((BandwidthRequest) request);
}
});
} catch (RegistryException e) {
throw new RuntimeException(e);
}
}
@Test
public void proposeScheduleSbnSubscriptionIsScheduledForNcf()
throws Exception {
proposeScheduleSbnSubscriptionThatFits();
final List<BandwidthAllocation> ncfSbnBandwidthAllocations = ncfBandwidthDao
.getBandwidthAllocations(Network.SBN);
assertThat(ncfSbnBandwidthAllocations,
is(not(emptyCollectionOf(BandwidthAllocation.class))));
}
@Test
public void proposeScheduleSbnSubscriptionIsScheduledForWfo()
throws Exception {
proposeScheduleSbnSubscriptionThatFits();
final List<BandwidthAllocation> wfoSbnBandwidthAllocations = bandwidthDao
.getBandwidthAllocations(Network.SBN);
assertThat(wfoSbnBandwidthAllocations,
is(not(emptyCollectionOf(BandwidthAllocation.class))));
}
@Test
public void tooLargeSbnSubscriptionIsNotScheduledForNcf() throws Exception {
proposeScheduleSbnSubscriptionThatDoesNotFit();
final List<BandwidthAllocation> ncfSbnBandwidthAllocations = ncfBandwidthDao
.getBandwidthAllocations(Network.SBN);
assertThat(ncfSbnBandwidthAllocations,
is(emptyCollectionOf(BandwidthAllocation.class)));
}
@Test
public void tooLargeSbnSubscriptionIsNotScheduledForWfo() throws Exception {
proposeScheduleSbnSubscriptionThatDoesNotFit();
final List<BandwidthAllocation> wfoSbnBandwidthAllocations = bandwidthDao
.getBandwidthAllocations(Network.SBN);
assertThat(wfoSbnBandwidthAllocations,
is(emptyCollectionOf(BandwidthAllocation.class)));
}
@Test
public void smallEnoughSbnSubscriptionCanBeScheduledForNcf()
throws Exception {
scheduleSbnSubscriptionThatFits();
final List<BandwidthSubscription> subscriptions = ncfBandwidthDao
.getBandwidthSubscriptions();
assertThat(subscriptions,
is(not(emptyCollectionOf(BandwidthSubscription.class))));
}
@Test
public void smallEnoughSbnSubscriptionCanBeScheduledForWfo()
throws Exception {
scheduleSbnSubscriptionThatFits();
final List<BandwidthSubscription> subscriptions = bandwidthDao
.getBandwidthSubscriptions();
assertThat(subscriptions,
is(not(emptyCollectionOf(BandwidthSubscription.class))));
}
/**
* Propose schedules an SBN routed subscription that will fit within the
* bandwidth requirements.
*
* @throws Exception
*/
private void proposeScheduleSbnSubscriptionThatFits() throws Exception {
scheduleSbnSubscription(createSubscriptionThatFillsAThirdOfABucket(),
RequestType.PROPOSE_SCHEDULE_SUBSCRIPTION);
}
/**
* Propose schedules an SBN routed subscription that will NOT fit within the
* bandwidth requirements.
*
* @throws Exception
*/
private void proposeScheduleSbnSubscriptionThatDoesNotFit()
throws Exception {
scheduleSbnSubscription(createSubscriptionThatFillsUpTwoBuckets(),
RequestType.PROPOSE_SCHEDULE_SUBSCRIPTION);
}
/**
* Schedules an SBN routed subscription that will fit within the bandwidth
* requirements.
*
* @throws Exception
*/
private void scheduleSbnSubscriptionThatFits() throws Exception {
scheduleSbnSubscription(createSubscriptionThatFillsAThirdOfABucket(),
RequestType.SCHEDULE_SUBSCRIPTION);
}
/**
* Schedules an SBN routed subscription that will NOT fit within the
* bandwidth requirements.
*
* @param requestType
*
* @throws Exception
*/
private void scheduleSbnSubscription(Subscription subscription,
RequestType requestType) throws Exception {
BandwidthRequest request = new BandwidthRequest();
request.setRequestType(requestType);
request.setNetwork(subscription.getRoute());
request.setSubscriptions(Arrays.asList(subscription));
bandwidthManager.handleRequest(request);
}
/**
* {@inheritDoc}
*/
@Override
protected Network getRouteToUseForSubscription() {
return Network.SBN;
}
}