private void singlePluginInstallAndRemove(String pluginShortName, String pluginCoordinates)
      throws IOException {
    logger.info("--> trying to download and install [{}]", pluginShortName);
    PluginManager pluginManager = pluginManager(pluginCoordinates);
    try {
      pluginManager.downloadAndExtract(pluginShortName);
      Path[] plugins = pluginManager.getListInstalledPlugins();
      assertThat(plugins, notNullValue());
      assertThat(plugins.length, is(1));

      // We remove it
      pluginManager.removePlugin(pluginShortName);
      plugins = pluginManager.getListInstalledPlugins();
      assertThat(plugins, notNullValue());
      assertThat(plugins.length, is(0));
    } catch (IOException e) {
      logger.warn(
          "--> IOException raised while downloading plugin [{}]. Skipping test.",
          e,
          pluginShortName);
    } catch (ElasticsearchTimeoutException e) {
      logger.warn(
          "--> timeout exception raised while downloading plugin [{}]. Skipping test.",
          pluginShortName);
    }
  }
 @Test(expected = ElasticsearchIllegalArgumentException.class)
 public void testRemovePluginWithURLForm() throws Exception {
   PluginManager pluginManager = pluginManager(null);
   pluginManager.removePlugin("file://whatever");
 }
  /** Test for #7890 */
  @Test
  public void testLocalPluginInstallWithBinAndConfigInAlreadyExistingConfigDir_7890()
      throws Exception {
    String pluginName = "plugin-test";
    Tuple<Settings, Environment> initialSettings =
        InternalSettingsPreparer.prepareSettings(
            ImmutableSettings.settingsBuilder().build(), false);
    Environment env = initialSettings.v2();

    Path configDir = env.configFile();
    if (!Files.exists(configDir)) {
      Files.createDirectories(configDir);
    }
    Path pluginConfigDir = configDir.resolve(pluginName);

    try {
      PluginManager pluginManager =
          pluginManager(getPluginUrlForResource("plugin_with_config_v1.zip"), initialSettings);
      pluginManager.downloadAndExtract(pluginName);

      Path[] plugins = pluginManager.getListInstalledPlugins();
      assertThat(plugins, arrayWithSize(1));

      /*
      First time, our plugin contains:
      - config/test.txt (version1)
       */
      assertFileContent(pluginConfigDir, "test.txt", "version1\n");

      // We now remove the plugin
      pluginManager.removePlugin(pluginName);
      // We should still have test.txt
      assertFileContent(pluginConfigDir, "test.txt", "version1\n");

      // Installing a new plugin version
      /*
      Second time, our plugin contains:
      - config/test.txt (version2)
      - config/dir/testdir.txt (version1)
      - config/dir/subdir/testsubdir.txt (version1)
       */
      pluginManager =
          pluginManager(getPluginUrlForResource("plugin_with_config_v2.zip"), initialSettings);
      pluginManager.downloadAndExtract(pluginName);

      assertFileContent(pluginConfigDir, "test.txt", "version1\n");
      assertFileContent(pluginConfigDir, "test.txt.new", "version2\n");
      assertFileContent(pluginConfigDir, "dir/testdir.txt", "version1\n");
      assertFileContent(pluginConfigDir, "dir/subdir/testsubdir.txt", "version1\n");

      // Removing
      pluginManager.removePlugin(pluginName);
      assertFileContent(pluginConfigDir, "test.txt", "version1\n");
      assertFileContent(pluginConfigDir, "test.txt.new", "version2\n");
      assertFileContent(pluginConfigDir, "dir/testdir.txt", "version1\n");
      assertFileContent(pluginConfigDir, "dir/subdir/testsubdir.txt", "version1\n");

      // Installing a new plugin version
      /*
      Third time, our plugin contains:
      - config/test.txt (version3)
      - config/test2.txt (version1)
      - config/dir/testdir.txt (version2)
      - config/dir/testdir2.txt (version1)
      - config/dir/subdir/testsubdir.txt (version2)
       */
      pluginManager =
          pluginManager(getPluginUrlForResource("plugin_with_config_v3.zip"), initialSettings);
      pluginManager.downloadAndExtract(pluginName);

      assertFileContent(pluginConfigDir, "test.txt", "version1\n");
      assertFileContent(pluginConfigDir, "test2.txt", "version1\n");
      assertFileContent(pluginConfigDir, "test.txt.new", "version3\n");
      assertFileContent(pluginConfigDir, "dir/testdir.txt", "version1\n");
      assertFileContent(pluginConfigDir, "dir/testdir.txt.new", "version2\n");
      assertFileContent(pluginConfigDir, "dir/testdir2.txt", "version1\n");
      assertFileContent(pluginConfigDir, "dir/subdir/testsubdir.txt", "version1\n");
      assertFileContent(pluginConfigDir, "dir/subdir/testsubdir.txt.new", "version2\n");
    } finally {
      // we need to clean up the copied dirs
      IOUtils.rm(pluginConfigDir);
    }
  }