Examples of AsyncRequestMap


Examples of org.globus.workspace.async.AsyncRequestMap

        logger.debug("persistOne");
        final Manager rm = this.locator.getManager();
        final Caller caller = this.populator().getCaller();

        PersistenceAdapter persistence = (PersistenceAdapter) applicationContext.getBean("nimbus-rm.persistence.PersistenceAdapter");
        AsyncRequestMap asyncRequestMap = new AsyncRequestMap(persistence);


        // Validate that we have a working AsyncRequestMap. It should be empty
        Collection<AsyncRequest> allRequests = asyncRequestMap.getAll();
        logger.debug("You have " + allRequests.size() + " requests.");
        assert(allRequests.size() == 0);

        // Test putting and getting from persistence
        String testID = "fake-id";
        Double testMaxBid = 42.0;
        boolean testSpotinstances = false;
        String testGroupID = "fake-group-id";
        boolean testIsPersistent = true;
        Caller testCaller = this.populator().getSuperuserCaller();
        Context context = null;
        String testSshKeyName = "fake-ssh-key";
        Calendar testCreationTime = Calendar.getInstance();
        testCreationTime.setTimeInMillis(424242424242l);
        String testNIC = "FakeName;FakeAssociation;FAKEMAC;NetMode;IPmethod;192.168.1.42;192.168.1.1;192.168.1.2;subnetmask;dns;hostname;null;null;null;null";
        VirtualMachine testVM = new VirtualMachine();
        testVM.setID(42);
        testVM.setName("fakename");
        testVM.setNetwork(testNIC);
        testVM.setPropagateRequired(false);
        testVM.setUnPropagateRequired(true);
        VirtualMachine[] testBindings = new VirtualMachine[1];
        testBindings[0] = testVM;
        int testAllocatedVM = 42;

        DataConvert dataConvert = new DataConvert(this.locator.getReprFactory());
        NIC[] testNICs = dataConvert.getNICs(testVM);
        logger.debug("Nics: " + testNICs[0]);

        //public AsyncRequest(String id, boolean spotinstances, Double spotPrice, boolean persistent, Caller caller, String groupID, VirtualMachine[] bindings, Context context, NIC[] requestedNics, String sshKeyName, Calendar creationTime) {
        AsyncRequest testRequest = new AsyncRequest(testID, testSpotinstances, testMaxBid, testIsPersistent, testCaller, testGroupID, testBindings, context, testNICs, testSshKeyName, testCreationTime);
        testRequest.addAllocatedVM(testAllocatedVM);
        asyncRequestMap.addOrReplace(testRequest);

        String secondID = "this-is-the-other-one";
        double secondMaxBid = 4.5;
        VirtualMachine[] secondBindings = new VirtualMachine[1];
        VirtualMachine secondVM = new VirtualMachine();
        secondVM.setID(52);
        secondBindings[0] = secondVM;

        AsyncRequest secondRequest = new AsyncRequest(secondID, testSpotinstances, secondMaxBid, testIsPersistent, testCaller, testGroupID, secondBindings, context, testNICs, testSshKeyName, testCreationTime);

        allRequests = asyncRequestMap.getAll();
        assert(allRequests != null);
        logger.debug("You have " + allRequests.size() + " requests.");
        assert(allRequests.size() == 1);

        // Note, the persistence layer just dumps the context, so we don't test for it

        AsyncRequest gotRequest = asyncRequestMap.getByID(testID);
        assertEquals(testID, gotRequest.getId());
        assertEquals(testMaxBid, gotRequest.getMaxBid());
        assertEquals(testSpotinstances, gotRequest.isSpotRequest());
        assertEquals(testGroupID, gotRequest.getGroupID());
        assertEquals(testIsPersistent, gotRequest.isPersistent());
        assertEquals(testCaller, gotRequest.getCaller());
        assertEquals(testSshKeyName, gotRequest.getSshKeyName());
        assertEquals(testCreationTime, gotRequest.getCreationTime());
        assertEquals(testVM.getID(), gotRequest.getBindings()[0].getID());
        assertEquals(testNICs[0].getIpAddress(), gotRequest.getRequestedNics()[0].getIpAddress());
        assertEquals(testAllocatedVM, gotRequest.getAllocatedVMs()[0]);
        assertEquals(AsyncRequestStatus.OPEN, gotRequest.getStatus());


        //Now Mutate the Map
        asyncRequestMap.addOrReplace(secondRequest);

        gotRequest.setStatus(AsyncRequestStatus.ACTIVE);
        asyncRequestMap.addOrReplace(gotRequest);

        AsyncRequest gotSecondRequest = asyncRequestMap.getByID(secondID);
        AsyncRequest updatedRequest = asyncRequestMap.getByID(testID);
        assertEquals(AsyncRequestStatus.ACTIVE, updatedRequest.getStatus());
        assertEquals(testAllocatedVM, updatedRequest.getAllocatedVMs()[0]);

        asyncRequestMap.addOrReplace(updatedRequest);
        AsyncRequest updatedRequest1 = asyncRequestMap.getByID(testID);
        assertEquals(testAllocatedVM, updatedRequest1.getAllocatedVMs()[0]);
        assertEquals(0, gotSecondRequest.getAllocatedVMs().length);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.