View Javadoc
1   package it.com.atlassian.plugin.osgi.performance;
2   
3   import com.atlassian.plugin.test.PluginJarBuilder;
4   
5   import java.io.File;
6   import java.util.Random;
7   
8   /**
9    * Tests the plugin framework handling restarts correctly
10   */
11  public class TestOsgiNoCacheFrameworkRestart extends FrameworkRestartTestBase {
12      private final Random rnd = new Random(System.currentTimeMillis());
13  
14      protected void addPlugin(File dir, int pluginId) throws Exception {
15          System.out.println("building plugin " + pluginId);
16          PluginJarBuilder builder = new PluginJarBuilder("restart-test", null);
17  
18          StringBuilder apxml = new StringBuilder();
19          apxml.append("<atlassian-plugin name='Test' key='test.plugin" + pluginId + "' pluginsVersion='2'>\n" +
20                  "    <plugin-info>\n" +
21                  "        <version>1.0</version>\n" +
22                  "    </plugin-info>\n" +
23                  //"    <component-import key='host1' interface='com.atlassian.plugin.osgi.SomeInterface' />\n" +
24                  "    <dummy key='dum1'/>\n");
25  
26          for (int x = 0; x < 50; x++) {
27              String pkg = pkg(pluginId, x);
28              builder.addFormattedJava(pkg + ".MyInterface",
29                      "package " + pkg + ";",
30                      "public interface MyInterface {}");
31              builder.addFormattedJava(pkg + ".MyComponent",
32                      "package " + pkg + ";",
33                      "public class MyComponent implements MyInterface {",
34                      "   public MyComponent() {}",
35                      "}");
36              apxml.append("  <component key='comp" + x + "' interface='" + pkg + ".MyInterface' class='" + pkg + ".MyComponent' ");
37              if (x < 10) {
38                  apxml.append("public='true'");
39              }
40              apxml.append("/>\n");
41          }
42          if (pluginId != 49) {
43  
44              for (int x = 0; x < 10; x++) {
45                  int refid;
46                  do {
47                      refid = 50 - rnd.nextInt(50 - pluginId) - 1;
48                  }
49                  while (refid == pluginId);
50  
51                  apxml.append("  <component-import key='ref" + x + "' interface='" + pkg(refid, x) + ".MyInterface'/>\n");
52              }
53          }
54          apxml.append("</atlassian-plugin>");
55          builder.addFormattedResource("atlassian-plugin.xml", apxml.toString());
56          builder.build(dir);
57          System.out.println("plugin " + pluginId + " built");
58      }
59  
60      private String pkg(int pluginId, int x) {
61          return "plugin" + pluginId + ".component" + x;
62      }
63  }