001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Aleksander V. Budniy
021: * @version $Revision: 1.6 $
022: */
023:
024: /**
025: * Created on 8.7.2005
026: */package org.apache.harmony.jpda.tests.jdwp.MultiSession;
027:
028: import org.apache.harmony.jpda.tests.framework.TestOptions;
029: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
030: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
031: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
032: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
033: import org.apache.harmony.jpda.tests.framework.jdwp.Value;
034: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
035: import org.apache.harmony.jpda.tests.jdwp.share.JDWPUnitDebuggeeWrapper;
036: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
037:
038: /**
039: * JDWP Unit test for verifying re-enabling of garbage collecting after re-connection.
040: */
041: public class EnableCollectionTest extends JDWPSyncTestCase {
042:
043: String checkedFieldName = "checkedObject";
044: static final int testStatusPassed = 0;
045: static final int testStatusFailed = -1;
046: static final String this CommandName = "MultiSession::EnableCollection command";
047:
048: static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/MultiSession/EnableCollectionDebuggee;";
049:
050: protected String getDebuggeeClassName() {
051: return "org.apache.harmony.jpda.tests.jdwp.MultiSession.EnableCollectionDebuggee";
052: }
053:
054: /**
055: * This testcase verifies re-enabling of garbage collecting after re-connection.
056: * <BR>It runs EnableCollectionDebuggee, disables garbage collecting for checked object
057: * with ObjectReference.DisableCollection command and re-connects.
058: * <BR>It is expected that checked object is garbage collected after re-connection.
059: */
060: public void testEnableCollection001() {
061: String this TestName = "testEnableCollection001";
062: logWriter.println("==> testEnableCollection001 started..");
063: synchronizer
064: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
065: finalSyncMessage = "TO_FINISH";
066:
067: long refTypeID = getClassIDBySignature(debuggeeSignature);
068:
069: logWriter.println("=> Debuggee class = "
070: + getDebuggeeClassName());
071: logWriter.println("=> referenceTypeID for Debuggee class = "
072: + refTypeID);
073:
074: long checkedFieldID = debuggeeWrapper.vmMirror.getFieldID(
075: refTypeID, checkedFieldName);
076:
077: logWriter
078: .println("=> Send ReferenceType::GetValues command for received fieldID and get ObjectID to check...");
079:
080: CommandPacket getValuesCommand = new CommandPacket(
081: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
082: JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
083: getValuesCommand.setNextValueAsReferenceTypeID(refTypeID);
084: getValuesCommand.setNextValueAsInt(1);
085: getValuesCommand.setNextValueAsFieldID(checkedFieldID);
086:
087: ReplyPacket getValuesReply = debuggeeWrapper.vmMirror
088: .performCommand(getValuesCommand);
089: getValuesCommand = null;
090: checkReplyPacket(getValuesReply,
091: "ReferenceType::GetValues command");
092:
093: int returnedValuesNumber = getValuesReply.getNextValueAsInt();
094: logWriter.println("=> Returned values number = "
095: + returnedValuesNumber);
096: assertEquals("Invalid returned number of values,", 1,
097: returnedValuesNumber);
098:
099: Value checkedObjectFieldValue = getValuesReply
100: .getNextValueAsValue();
101: byte checkedObjectFieldTag = checkedObjectFieldValue.getTag();
102: logWriter
103: .println("=> Returned field value tag for checked object= "
104: + checkedObjectFieldTag
105: + "("
106: + JDWPConstants.Tag
107: .getName(checkedObjectFieldTag) + ")");
108: assertEquals("Invalid object tag,",
109: JDWPConstants.Tag.OBJECT_TAG, checkedObjectFieldTag);
110:
111: long checkedObjectID = checkedObjectFieldValue.getLongValue();
112: logWriter.println("=> Returned checked ObjectID = "
113: + checkedObjectID);
114:
115: logWriter.println("\n=> CHECK: send " + this CommandName
116: + " for checked ObjectID...");
117:
118: CommandPacket checkedCommand = new CommandPacket(
119: JDWPCommands.ObjectReferenceCommandSet.CommandSetID,
120: JDWPCommands.ObjectReferenceCommandSet.DisableCollectionCommand);
121: checkedCommand.setNextValueAsObjectID(checkedObjectID);
122:
123: ReplyPacket checkedReply = debuggeeWrapper.vmMirror
124: .performCommand(checkedCommand);
125: checkedCommand = null;
126: checkReplyPacket(checkedReply,
127: "ObjectReference::DisableCollection command");
128:
129: logWriter
130: .println("=> CHECK: Reply is received without any error");
131:
132: logWriter.println("");
133: logWriter.println("=> CLOSE CONNECTION..");
134: closeConnection();
135: logWriter.println("=> CONNECTION CLOSED");
136: logWriter.println("");
137: logWriter.println("=> OPEN NEW CONNECTION..");
138: openConnection();
139: logWriter.println("=> CONNECTION OPENED");
140:
141: logWriter.println("=> Resuming debuggee");
142:
143: // start the thread
144: finalSyncMessage = null;
145: synchronizer
146: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
147:
148: String messageFromDebuggee = synchronizer.receiveMessage();
149: logWriter.println("\n=> Received message from Debuggee = \""
150: + messageFromDebuggee + "\"");
151: if (messageFromDebuggee
152: .equals("Checked Object is NOT UNLOADed; Pattern Object is UNLOADed;")) {
153: logWriter
154: .println("## FAILURE: Checked Object is NOT UNLOADed after "
155: + this CommandName);
156: fail("Invalid message from debuggee.");
157: } else {
158: logWriter.println("=> PASSED: It is expected result");
159: }
160:
161: assertAllDataRead(checkedReply);
162:
163: logWriter.println("=> Send to Debuggee signal to finish ...");
164: synchronizer
165: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
166: logWriter.println("==> " + this TestName + " for "
167: + this CommandName + ": FINISH");
168: logWriter.println("==> testEnableCollection001 PASSED!");
169: }
170:
171: protected void beforeDebuggeeStart(
172: JDWPUnitDebuggeeWrapper debuggeeWrapper) {
173: settings.setAttachConnectorKind();
174: if (settings.getTransportAddress() == null) {
175: settings
176: .setTransportAddress(TestOptions.DEFAULT_ATTACHING_ADDRESS);
177: }
178: logWriter.println("ATTACH connector kind");
179: super .beforeDebuggeeStart(debuggeeWrapper);
180: }
181:
182: public static void main(String[] args) {
183: junit.textui.TestRunner.run(EnableCollectionTest.class);
184: }
185: }
|