Home | History | Annotate | Download | only in MultiSession
      1 /*
      2  * Licensed to the Apache Software Foundation (ASF) under one or more
      3  * contributor license agreements.  See the NOTICE file distributed with
      4  * this work for additional information regarding copyright ownership.
      5  * The ASF licenses this file to You under the Apache License, Version 2.0
      6  * (the "License"); you may not use this file except in compliance with
      7  * 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, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *
     15  *  See the License for the specific language governing permissions and
     16  *  limitations under the License.
     17  */
     18 
     19 /**
     20  * @author Aleksander V. Budniy
     21  */
     22 
     23 /**
     24  * Created on 8.7.2005
     25  */
     26 package org.apache.harmony.jpda.tests.jdwp.MultiSession;
     27 
     28 import org.apache.harmony.jpda.tests.framework.TestOptions;
     29 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
     30 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
     31 import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent;
     32 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
     33 
     34 
     35 /**
     36  * JDWP Unit test for verifying canceling of FIELD_MODIFICATION event after re-connection.
     37  */
     38 public class FieldModificationTest extends JDWPEventTestCase {
     39 
     40     @Override
     41     protected String getDebuggeeClassName() {
     42         return FieldDebuggee.class.getName();
     43     }
     44 
     45     /**
     46      * This testcase verifies canceling of FIELD_MODIFICATION event after re-connection.
     47      * <BR>It runs FieldDebuggee, sets request for FIELD_MODIFICATION event
     48      * and re-connects.
     49      * <BR>It is expected that only auto VM_DEATH event occurs after re-connection,
     50      * but no any other event, including FIELD_MODIFICATION.
     51      */
     52     public void testFieldModification001() {
     53 
     54         logWriter.println("==> testFieldModification001 started");
     55 
     56         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
     57 
     58         String classSignature = "Lorg/apache/harmony/jpda/tests/jdwp/MultiSession/FieldDebuggee;";
     59         debuggeeWrapper.vmMirror.setFieldModification(classSignature,
     60                 JDWPConstants.TypeTag.CLASS, "testIntField");
     61 
     62         logWriter.println("");
     63         logWriter.println("=> CLOSE CONNECTION..");
     64         closeConnection();
     65         logWriter.println("=> CONNECTION CLOSED");
     66 
     67         logWriter.println("");
     68         logWriter.println("=> OPEN NEW CONNECTION..");
     69         openConnection();
     70         logWriter.println("=> CONNECTION OPENED");
     71 
     72         logWriter.println("=> Resuming debuggee");
     73 
     74         // start the thread
     75         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
     76         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
     77 
     78         //      receive event
     79         logWriter.println("=> Wait for event..");
     80         CommandPacket eventPacket = debuggeeWrapper.vmMirror.receiveEvent();
     81         ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(eventPacket);
     82         int eventsCount = parsedEvents.length;
     83         logWriter.println("=> Received event set: count=" + eventsCount);
     84 
     85         //ckeck if received events are expected
     86         int result = 0;
     87         for (int i = 0; i < eventsCount; i++) {
     88             ParsedEvent event = parsedEvents[i];
     89             logWriter.println("=> Event #" + i + ";");
     90 
     91             // print event info
     92             byte eventSuspendPolicy = event.getSuspendPolicy();
     93             logWriter.println("=> SuspendPolicy=" + eventSuspendPolicy + "/"
     94                     + JDWPConstants.SuspendPolicy.getName(eventSuspendPolicy));
     95             byte eventKind = event.getEventKind();
     96             logWriter.println("=> EventKind=" + eventKind + "/"
     97                     + JDWPConstants.EventKind.getName(eventKind));
     98             int eventRequestID = event.getRequestID();
     99             logWriter.println("=> RequestID=" + eventRequestID);
    100 
    101             // check if event is expected
    102             if (eventKind == JDWPConstants.EventKind.VM_DEATH) {
    103                 if (parsedEvents[i].getRequestID() == 0) {
    104                     logWriter.println("=> found auto VM_DEATH event!");
    105                     // for automatical event suspend policy can be changed
    106                 } else {
    107                     logWriter.println("## FAILURE: VM_DEATH event "
    108                             + "with unexpected RequestID: " + eventRequestID);
    109                     result = 1;
    110                 }
    111             } else {
    112                 logWriter.println("## FAILURE: unexpected event kind: "
    113                         + eventKind);
    114                 result = 2;
    115             }
    116         }
    117 
    118         if (1 == result)
    119             fail("VM_DEATH event with unexpected RequestID");
    120         else if (2 == result)
    121             fail("Unexpected event kind");
    122 
    123         logWriter.println("==> testFieldModification001 PASSED!");
    124     }
    125 
    126     @Override
    127     protected void beforeConnectionSetUp() {
    128         settings.setAttachConnectorKind();
    129         if (settings.getTransportAddress() == null) {
    130             settings.setTransportAddress(TestOptions.DEFAULT_ATTACHING_ADDRESS);
    131         }
    132         logWriter.println("ATTACH connector kind");
    133         super.beforeConnectionSetUp();
    134     }
    135 }
    136