View Javadoc

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