01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tctest;
06:
07: import com.tc.asm.ClassAdapter;
08: import com.tc.asm.ClassVisitor;
09: import com.tc.asm.MethodVisitor;
10: import com.tc.asm.Opcodes;
11: import com.tctest.runner.TransparentAppConfig;
12:
13: import java.util.HashMap;
14: import java.util.Map;
15:
16: public class RootClassChangeTest extends TransparentTestBase {
17: public static final int MUTATOR_NODE_COUNT = 2;
18: public static final int ADAPTED_MUTATOR_COUNT = 1;
19:
20: public void doSetUp(TransparentTestIface t) throws Exception {
21: TransparentAppConfig tac = t.getTransparentAppConfig();
22: tac.setClientCount(MUTATOR_NODE_COUNT).setIntensity(1)
23: .setAdaptedMutatorCount(ADAPTED_MUTATOR_COUNT);
24:
25: Map adapterMap = new HashMap();
26: adapterMap.put(RootClassChangeTestApp.DeepLargeObject.class
27: .getName(), DeepLargeObjectAdapter.class);
28: tac
29: .setAttribute(TransparentAppConfig.adapterMapKey,
30: adapterMap);
31:
32: t.initializeTestRunner();
33: }
34:
35: protected Class getApplicationClass() {
36: return RootClassChangeTestApp.class;
37: }
38:
39: public static class DeepLargeObjectAdapter extends ClassAdapter {
40:
41: private String owner;
42:
43: public DeepLargeObjectAdapter(ClassVisitor cv) {
44: super (cv);
45: }
46:
47: public void visitEnd() {
48: super .visitField(Opcodes.ACC_PRIVATE, "foo",
49: "Lcom/tctest/RootClassChangeTestApp$FooObject;",
50: null, null);
51: super .visitEnd();
52: }
53:
54: public void visit(int version, int access, String name,
55: String signature, String super Name, String[] interfaces) {
56: super .visit(version, access, name, signature, super Name,
57: interfaces);
58: owner = name;
59: }
60:
61: public MethodVisitor visitMethod(int access, String name,
62: String desc, String signature, String[] exceptions) {
63: MethodVisitor visitor = super .visitMethod(access, name,
64: desc, signature, exceptions);
65: if (name.equals("setFooObject")) {
66: visitor.visitCode();
67: visitor.visitVarInsn(Opcodes.ALOAD, 0);
68: visitor.visitTypeInsn(Opcodes.NEW,
69: "com/tctest/RootClassChangeTestApp$FooObject");
70: visitor.visitInsn(Opcodes.DUP);
71: visitor.visitLdcInsn("Yeah");
72: visitor.visitInsn(Opcodes.ICONST_5);
73: visitor.visitMethodInsn(Opcodes.INVOKESPECIAL,
74: "com/tctest/RootClassChangeTestApp$FooObject",
75: "<init>", "(Ljava/lang/String;I)V");
76: visitor
77: .visitFieldInsn(Opcodes.PUTFIELD, owner, "foo",
78: "Lcom/tctest/RootClassChangeTestApp$FooObject;");
79: visitor.visitInsn(Opcodes.RETURN);
80: visitor.visitMaxs(0, 0);
81: visitor.visitEnd();
82: return null;
83: } else if (name.equals("getFooObject")) {
84: visitor.visitCode();
85: visitor.visitVarInsn(Opcodes.ALOAD, 0);
86: visitor
87: .visitFieldInsn(Opcodes.GETFIELD, owner, "foo",
88: "Lcom/tctest/RootClassChangeTestApp$FooObject;");
89: visitor.visitInsn(Opcodes.ARETURN);
90: visitor.visitMaxs(0, 0);
91: visitor.visitEnd();
92: return null;
93: }
94: return visitor;
95: }
96: }
97: }
|