Search in sources :

Example 61 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project hazelcast by hazelcast.

the class OperatingSystemMetricSetTest method assumeOperatingSystemMXBeanType.

private void assumeOperatingSystemMXBeanType(String expected) {
    OperatingSystemMXBean bean = ManagementFactory.getOperatingSystemMXBean();
    try {
        Class<?> expectedInterface = Class.forName(expected);
        assumeTrue(expectedInterface.isAssignableFrom(bean.getClass()));
    } catch (ClassNotFoundException e) {
        throw new AssumptionViolatedException("MXBean interface " + expected + " was not found");
    }
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 62 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project hazelcast by hazelcast.

the class AbstractPbeReplacerTest method assumeAlgorithmsSupported.

protected void assumeAlgorithmsSupported(String secretKeyFactory, String cipher) {
    try {
        SecretKeyFactory.getInstance(secretKeyFactory);
        Cipher.getInstance(cipher);
    } catch (Exception e) {
        throw new AssumptionViolatedException("Skipping - Unsupported algorithm", e);
    }
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) AssumptionViolatedException(org.junit.AssumptionViolatedException)

Example 63 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project brave by openzipkin.

the class ITSpringRabbit method startRabbit.

@BeforeClass
public static void startRabbit() {
    if ("true".equals(System.getProperty("docker.skip"))) {
        throw new AssumptionViolatedException("Skipping startup of docker " + IMAGE);
    }
    try {
        LOGGER.info("Starting docker image " + IMAGE);
        rabbit = new RabbitMQContainer(IMAGE);
        rabbit.start();
    } catch (Throwable e) {
        throw new AssumptionViolatedException("Couldn't start docker image " + IMAGE + ": " + e.getMessage(), e);
    }
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory(rabbit.getContainerIpAddress(), rabbit.getMappedPort(RABBIT_PORT));
    try {
        RabbitAdmin amqpAdmin = new RabbitAdmin(connectionFactory);
        amqpAdmin.declareExchange(exchange);
        amqpAdmin.declareQueue(queue);
        amqpAdmin.declareBinding(binding);
        amqpAdmin.declareExchange(exchange_batch);
        amqpAdmin.declareQueue(queue_batch);
        amqpAdmin.declareBinding(binding_batch);
        amqpAdmin.declareExchange(exchange_request_reply);
        amqpAdmin.declareQueue(queue_request);
        amqpAdmin.declareQueue(queue_reply);
        amqpAdmin.declareBinding(binding_request);
        amqpAdmin.declareBinding(binding_reply);
    } finally {
        connectionFactory.destroy();
    }
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) CachingConnectionFactory(org.springframework.amqp.rabbit.connection.CachingConnectionFactory) RabbitAdmin(org.springframework.amqp.rabbit.core.RabbitAdmin) BeforeClass(org.junit.BeforeClass)

Example 64 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project acceptance-test-harness by jenkinsci.

the class PluginManager method installPlugins.

/**
 * Installs specified plugins.
 *
 * @deprecated Please be encouraged to use {@link WithPlugins} annotations to statically declare
 * the required plugins you need. If you really do need to install plugins in the middle
 * of a test, as opposed to be in the beginning, then this is the right method.
 * <p/>
 * The deprecation marker is to call attention to {@link WithPlugins}. This method
 * is not really deprecated.
 * @return Always false.
 */
@Deprecated
public boolean installPlugins(final PluginSpec... specs) throws UnableToResolveDependencies, IOException {
    final Map<String, String> candidates = getMapShortNamesVersion(specs);
    if (!updated) {
        checkForUpdates();
    }
    if (uploadPlugins) {
        LOGGER.warning("Installing plugins by direct upload. Better to use the default MockUpdateCenter.");
        // First check to see whether we need to do anything.
        // If not, do not consider transitive dependencies of the requested plugins,
        // which might force updates (and thus restarts) even though we already have
        // a sufficiently new version of the requested plugin.
        boolean someChangeRequired = false;
        for (PluginSpec spec : specs) {
            if (installationStatus(spec) != InstallationStatus.UP_TO_DATE) {
                someChangeRequired = true;
                break;
            }
        }
        if (!someChangeRequired) {
            return false;
        }
        List<PluginMetadata> pluginToBeInstalled = ucmd.get(jenkins).transitiveDependenciesOf(jenkins, Arrays.asList(specs));
        for (PluginMetadata newPlugin : pluginToBeInstalled) {
            final String name = newPlugin.getName();
            String requiredVersion = candidates.get(name);
            String availableVersion = newPlugin.getVersion();
            if (requiredVersion == null) {
                // a dependency
                requiredVersion = availableVersion;
            }
            final String currentSpec = StringUtils.isNotEmpty(requiredVersion) ? name + "@" + requiredVersion : name;
            InstallationStatus status = installationStatus(currentSpec);
            if (status != InstallationStatus.UP_TO_DATE) {
                if (new VersionNumber(requiredVersion).compareTo(new VersionNumber(availableVersion)) > 0) {
                    throw new AssumptionViolatedException(name + " has version " + availableVersion + " but " + requiredVersion + " was requested");
                }
                try {
                    newPlugin.uploadTo(jenkins, injector, availableVersion);
                } catch (ArtifactResolutionException x) {
                    throw new UnableToResolveDependencies(x);
                }
            }
        }
    } else {
        // JENKINS-50790 It seems that this page takes too much time to load when running in the new ci.jenkins.io
        try {
            driver.manage().timeouts().pageLoadTimeout(time.seconds(240), TimeUnit.MILLISECONDS);
            visit("available");
        } finally {
            driver.manage().timeouts().pageLoadTimeout(time.seconds(FallbackConfig.PAGE_LOAD_TIMEOUT), TimeUnit.MILLISECONDS);
        }
        // End JENKINS-50790
        final ArrayList<PluginSpec> update = new ArrayList<>();
        for (final PluginSpec n : specs) {
            switch(installationStatus(n)) {
                case NOT_INSTALLED:
                    tickPluginToInstall(n);
                    break;
                case OUTDATED:
                    update.add(n);
                    break;
                case UP_TO_DATE:
                    // Nothing to do
                    break;
                default:
                    assert false : "Unreachable";
            }
        }
        clickButton("Install");
        // Plugins that are already installed in older version will be updated
        System.out.println("Plugins to be updated: " + update);
        if (!update.isEmpty()) {
            // Updates tab
            visit("");
            for (PluginSpec n : update) {
                tickPluginToInstall(n);
            }
            clickButton("Download now and install after restart");
        }
    }
    // Jenkins will be restarted if necessary
    boolean hasBeenRestarted = new UpdateCenter(jenkins).waitForInstallationToComplete(specs);
    if (!hasBeenRestarted && specs.length > 0 && jenkins.getVersion().isNewerThan(new VersionNumber("2.188"))) {
        jenkins.getLogger("all").waitForLogged(Pattern.compile("Completed installation of .*"), 1000);
    }
    return false;
}
Also used : MockUpdateCenter(org.jenkinsci.test.acceptance.update_center.MockUpdateCenter) AssumptionViolatedException(org.junit.AssumptionViolatedException) ArrayList(java.util.ArrayList) VersionNumber(hudson.util.VersionNumber) PluginSpec(org.jenkinsci.test.acceptance.update_center.PluginSpec) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) UnableToResolveDependencies(org.jenkinsci.test.acceptance.update_center.UpdateCenterMetadata.UnableToResolveDependencies) PluginMetadata(org.jenkinsci.test.acceptance.update_center.PluginMetadata)

Example 65 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project acceptance-test-harness by jenkinsci.

the class PluginManager method tickPluginToInstall.

private void tickPluginToInstall(PluginSpec spec) {
    String name = spec.getName();
    WebElement filterBox = find(By.id("filter-box"));
    filterBox.clear();
    filterBox.sendKeys(name);
    // the target plugin web element becomes stale due to the dynamic behaviour of the plugin
    // manager UI which ends up with StaleElementReferenceException.
    // This is re-trying until the element can be properly checked.
    waitFor().withTimeout(10, TimeUnit.SECONDS).until(() -> {
        try {
            check(find(by.xpath("//input[starts-with(@name,'plugin.%s.')]", name)));
        } catch (NoSuchElementException | StaleElementReferenceException e) {
            return false;
        }
        return true;
    });
    final VersionNumber requiredVersion = spec.getVersionNumber();
    if (requiredVersion != null) {
        final VersionNumber availableVersion = getAvailableVersionForPlugin(name);
        if (availableVersion.isOlderThan(requiredVersion)) {
            throw new AssumptionViolatedException(String.format("Version '%s' of '%s' is required, but available version is '%s'", requiredVersion, name, availableVersion));
        }
    }
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) StaleElementReferenceException(org.openqa.selenium.StaleElementReferenceException) WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException) VersionNumber(hudson.util.VersionNumber)

Aggregations

AssumptionViolatedException (org.junit.AssumptionViolatedException)79 Test (org.junit.Test)26 IOException (java.io.IOException)16 Statement (org.junit.runners.model.Statement)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Method (java.lang.reflect.Method)6 Set (java.util.Set)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 File (java.io.File)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 ZipEntry (java.util.zip.ZipEntry)5 ZipOutputStream (java.util.zip.ZipOutputStream)5 InputStream (java.io.InputStream)4 HashSet (java.util.HashSet)4 ZipInputStream (java.util.zip.ZipInputStream)4 FilterInputStream (java.io.FilterInputStream)3 UnknownHostException (java.net.UnknownHostException)3 JarInputStream (java.util.jar.JarInputStream)3 Configuration (org.apache.flink.configuration.Configuration)3 IInjectorProvider (org.eclipse.xtext.junit4.IInjectorProvider)3