Search in sources :

Example 26 with Signal

use of sun.misc.Signal in project jdk8u_jdk by JetBrains.

the class Terminator method setup.

/* Invocations of setup and teardown are already synchronized
     * on the shutdown lock, so no further synchronization is needed here
     */
static void setup() {
    if (handler != null)
        return;
    SignalHandler sh = new SignalHandler() {

        public void handle(Signal sig) {
            Shutdown.exit(sig.getNumber() + 0200);
        }
    };
    handler = sh;
    // System.exit()
    try {
        Signal.handle(new Signal("INT"), sh);
    } catch (IllegalArgumentException e) {
    }
    try {
        Signal.handle(new Signal("TERM"), sh);
    } catch (IllegalArgumentException e) {
    }
}
Also used : Signal(sun.misc.Signal) SignalHandler(sun.misc.SignalHandler)

Example 27 with Signal

use of sun.misc.Signal in project jdepth by Crab2died.

the class SignalCatch method main.

public static void main(String... args) throws IOException {
    SignalHandler handler = new SignalCatch();
    handler.handle(new Signal("TERM"));
    handler.handle(new Signal("SEGV"));
    handler.handle(new Signal("ILL"));
    handler.handle(new Signal("FPE"));
    handler.handle(new Signal("ABRT"));
    handler.handle(new Signal("INT"));
    handler.handle(new Signal("BREAK"));
}
Also used : Signal(sun.misc.Signal) SignalHandler(sun.misc.SignalHandler)

Example 28 with Signal

use of sun.misc.Signal in project evosuite by EvoSuite.

the class PropertiesNoveltySearchFactory method getSearchAlgorithm.

@Override
public // public GeneticAlgorithm<TestChromosome> getSearchAlgorithm() {
NoveltySearch<TestChromosome> getSearchAlgorithm() {
    ChromosomeFactory<TestChromosome> factory = getChromosomeFactory();
    NoveltySearch<TestChromosome> ga = new NoveltySearch<>(factory);
    if (Properties.NEW_STATISTICS)
        ga.addListener(new StatisticsListener());
    // How to select candidates for reproduction
    SelectionFunction<TestChromosome> selectionFunction = getSelectionFunction();
    selectionFunction.setMaximize(false);
    ga.setSelectionFunction(selectionFunction);
    // When to stop the search
    StoppingCondition stopping_condition = getStoppingCondition();
    ga.setStoppingCondition(stopping_condition);
    // ga.addListener(stopping_condition);
    if (Properties.STOP_ZERO) {
        ga.addStoppingCondition(new ZeroFitnessStoppingCondition());
    }
    if (!(stopping_condition instanceof MaxTimeStoppingCondition)) {
        ga.addStoppingCondition(new GlobalTimeStoppingCondition());
    }
    if (ArrayUtil.contains(Properties.CRITERION, Properties.Criterion.MUTATION) || ArrayUtil.contains(Properties.CRITERION, Properties.Criterion.STRONGMUTATION)) {
        if (Properties.STRATEGY == Properties.Strategy.ONEBRANCH)
            ga.addStoppingCondition(new MutationTimeoutStoppingCondition());
        else
            ga.addListener(new MutationTestPool());
    // } else if (Properties.CRITERION == Criterion.DEFUSE) {
    // if (Properties.STRATEGY == Strategy.EVOSUITE)
    // ga.addListener(new DefUseTestPool());
    }
    ga.resetStoppingConditions();
    ga.setPopulationLimit(getPopulationLimit());
    // How to cross over
    CrossOverFunction crossover_function = getCrossoverFunction();
    ga.setCrossOverFunction(crossover_function);
    if (Properties.CHECK_BEST_LENGTH) {
        RelativeSuiteLengthBloatControl bloat_control = new org.evosuite.testsuite.RelativeSuiteLengthBloatControl();
        ga.addBloatControl(bloat_control);
        ga.addListener(bloat_control);
    }
    // ga.addBloatControl(new MaxLengthBloatControl());
    TestCaseSecondaryObjective.setSecondaryObjectives();
    if (Properties.DYNAMIC_LIMIT) {
        // max_s = GAProperties.generations * getBranches().size();
        // TODO: might want to make this dependent on the selected coverage
        // criterion
        // TODO also, question: is branchMap.size() really intended here?
        // I think BranchPool.getBranchCount() was intended
        Properties.SEARCH_BUDGET = Properties.SEARCH_BUDGET * (BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getNumBranchlessMethods(Properties.TARGET_CLASS) + BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranchCountForClass(Properties.TARGET_CLASS) * 2);
        stopping_condition.setLimit(Properties.SEARCH_BUDGET);
        logger.info("Setting dynamic length limit to " + Properties.SEARCH_BUDGET);
    }
    if (Properties.LOCAL_SEARCH_RESTORE_COVERAGE) {
        org.evosuite.ga.metaheuristics.SearchListener map = BranchCoverageMap.getInstance();
        ga.addListener(map);
    }
    if (Properties.SHUTDOWN_HOOK) {
        // ShutdownTestWriter writer = new
        // ShutdownTestWriter(Thread.currentThread());
        ShutdownTestWriter writer = new ShutdownTestWriter();
        ga.addStoppingCondition(writer);
        RMIStoppingCondition rmi = RMIStoppingCondition.getInstance();
        ga.addStoppingCondition(rmi);
        if (Properties.STOPPING_PORT != -1) {
            SocketStoppingCondition ss = new SocketStoppingCondition();
            ss.accept();
            ga.addStoppingCondition(ss);
        }
        // Runtime.getRuntime().addShutdownHook(writer);
        Signal.handle(new Signal("INT"), writer);
    }
    ga.addListener(new ResourceController());
    return ga;
}
Also used : ZeroFitnessStoppingCondition(org.evosuite.ga.stoppingconditions.ZeroFitnessStoppingCondition) MutationTestPool(org.evosuite.coverage.mutation.MutationTestPool) NoveltySearch(org.evosuite.ga.metaheuristics.NoveltySearch) StatisticsListener(org.evosuite.statistics.StatisticsListener) MaxTimeStoppingCondition(org.evosuite.ga.stoppingconditions.MaxTimeStoppingCondition) RelativeSuiteLengthBloatControl(org.evosuite.testsuite.RelativeSuiteLengthBloatControl) ShutdownTestWriter(org.evosuite.ShutdownTestWriter) CrossOverFunction(org.evosuite.ga.operators.crossover.CrossOverFunction) Signal(sun.misc.Signal) MutationTimeoutStoppingCondition(org.evosuite.coverage.mutation.MutationTimeoutStoppingCondition) SocketStoppingCondition(org.evosuite.ga.stoppingconditions.SocketStoppingCondition) RMIStoppingCondition(org.evosuite.ga.stoppingconditions.RMIStoppingCondition) ZeroFitnessStoppingCondition(org.evosuite.ga.stoppingconditions.ZeroFitnessStoppingCondition) StoppingCondition(org.evosuite.ga.stoppingconditions.StoppingCondition) MaxTimeStoppingCondition(org.evosuite.ga.stoppingconditions.MaxTimeStoppingCondition) GlobalTimeStoppingCondition(org.evosuite.ga.stoppingconditions.GlobalTimeStoppingCondition) MutationTimeoutStoppingCondition(org.evosuite.coverage.mutation.MutationTimeoutStoppingCondition) SocketStoppingCondition(org.evosuite.ga.stoppingconditions.SocketStoppingCondition) ResourceController(org.evosuite.utils.ResourceController) RMIStoppingCondition(org.evosuite.ga.stoppingconditions.RMIStoppingCondition) TestChromosome(org.evosuite.testcase.TestChromosome) GlobalTimeStoppingCondition(org.evosuite.ga.stoppingconditions.GlobalTimeStoppingCondition)

Example 29 with Signal

use of sun.misc.Signal in project evosuite by EvoSuite.

the class PropertiesSuiteGAFactory method getSearchAlgorithm.

@Override
public GeneticAlgorithm<TestSuiteChromosome> getSearchAlgorithm() {
    ChromosomeFactory<TestSuiteChromosome> factory = getChromosomeFactory();
    // FIXXME
    GeneticAlgorithm<TestSuiteChromosome> ga = getGeneticAlgorithm(factory);
    if (Properties.NEW_STATISTICS)
        ga.addListener(new StatisticsListener());
    // How to select candidates for reproduction
    SelectionFunction<TestSuiteChromosome> selectionFunction = getSelectionFunction();
    selectionFunction.setMaximize(false);
    ga.setSelectionFunction(selectionFunction);
    // When to stop the search
    StoppingCondition stopping_condition = getStoppingCondition();
    ga.setStoppingCondition(stopping_condition);
    // ga.addListener(stopping_condition);
    if (Properties.STOP_ZERO) {
        ga.addStoppingCondition(new ZeroFitnessStoppingCondition());
    }
    if (!(stopping_condition instanceof MaxTimeStoppingCondition)) {
        ga.addStoppingCondition(new GlobalTimeStoppingCondition());
    }
    if (ArrayUtil.contains(Properties.CRITERION, Criterion.MUTATION) || ArrayUtil.contains(Properties.CRITERION, Criterion.STRONGMUTATION)) {
        if (Properties.STRATEGY == Strategy.ONEBRANCH)
            ga.addStoppingCondition(new MutationTimeoutStoppingCondition());
        else
            ga.addListener(new MutationTestPool());
    // } else if (Properties.CRITERION == Criterion.DEFUSE) {
    // if (Properties.STRATEGY == Strategy.EVOSUITE)
    // ga.addListener(new DefUseTestPool());
    }
    ga.resetStoppingConditions();
    ga.setPopulationLimit(getPopulationLimit());
    // How to cross over
    CrossOverFunction crossover_function = getCrossoverFunction();
    ga.setCrossOverFunction(crossover_function);
    if (Properties.CHECK_BEST_LENGTH) {
        RelativeSuiteLengthBloatControl bloat_control = new org.evosuite.testsuite.RelativeSuiteLengthBloatControl();
        ga.addBloatControl(bloat_control);
        ga.addListener(bloat_control);
    }
    // ga.addBloatControl(new MaxLengthBloatControl());
    TestSuiteSecondaryObjective.setSecondaryObjectives();
    if (Properties.DYNAMIC_LIMIT) {
        // max_s = GAProperties.generations * getBranches().size();
        // TODO: might want to make this dependent on the selected coverage
        // criterion
        // TODO also, question: is branchMap.size() really intended here?
        // I think BranchPool.getBranchCount() was intended
        Properties.SEARCH_BUDGET = Properties.SEARCH_BUDGET * (BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getNumBranchlessMethods(Properties.TARGET_CLASS) + BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranchCountForClass(Properties.TARGET_CLASS) * 2);
        stopping_condition.setLimit(Properties.SEARCH_BUDGET);
        logger.info("Setting dynamic length limit to " + Properties.SEARCH_BUDGET);
    }
    if (Properties.LOCAL_SEARCH_RESTORE_COVERAGE) {
        org.evosuite.ga.metaheuristics.SearchListener map = BranchCoverageMap.getInstance();
        ga.addListener(map);
    }
    if (Properties.SHUTDOWN_HOOK) {
        // ShutdownTestWriter writer = new
        // ShutdownTestWriter(Thread.currentThread());
        ShutdownTestWriter writer = new ShutdownTestWriter();
        ga.addStoppingCondition(writer);
        RMIStoppingCondition rmi = RMIStoppingCondition.getInstance();
        ga.addStoppingCondition(rmi);
        if (Properties.STOPPING_PORT != -1) {
            SocketStoppingCondition ss = new SocketStoppingCondition();
            ss.accept();
            ga.addStoppingCondition(ss);
        }
        // Runtime.getRuntime().addShutdownHook(writer);
        Signal.handle(new Signal("INT"), writer);
    }
    ga.addListener(new ResourceController());
    return ga;
}
Also used : ZeroFitnessStoppingCondition(org.evosuite.ga.stoppingconditions.ZeroFitnessStoppingCondition) MutationTestPool(org.evosuite.coverage.mutation.MutationTestPool) StatisticsListener(org.evosuite.statistics.StatisticsListener) MaxTimeStoppingCondition(org.evosuite.ga.stoppingconditions.MaxTimeStoppingCondition) RelativeSuiteLengthBloatControl(org.evosuite.testsuite.RelativeSuiteLengthBloatControl) org.evosuite.ga.metaheuristics(org.evosuite.ga.metaheuristics) ShutdownTestWriter(org.evosuite.ShutdownTestWriter) CrossOverFunction(org.evosuite.ga.operators.crossover.CrossOverFunction) Signal(sun.misc.Signal) MutationTimeoutStoppingCondition(org.evosuite.coverage.mutation.MutationTimeoutStoppingCondition) SocketStoppingCondition(org.evosuite.ga.stoppingconditions.SocketStoppingCondition) ZeroFitnessStoppingCondition(org.evosuite.ga.stoppingconditions.ZeroFitnessStoppingCondition) StoppingCondition(org.evosuite.ga.stoppingconditions.StoppingCondition) MaxTimeStoppingCondition(org.evosuite.ga.stoppingconditions.MaxTimeStoppingCondition) RMIStoppingCondition(org.evosuite.ga.stoppingconditions.RMIStoppingCondition) GlobalTimeStoppingCondition(org.evosuite.ga.stoppingconditions.GlobalTimeStoppingCondition) MutationTimeoutStoppingCondition(org.evosuite.coverage.mutation.MutationTimeoutStoppingCondition) SocketStoppingCondition(org.evosuite.ga.stoppingconditions.SocketStoppingCondition) ResourceController(org.evosuite.utils.ResourceController) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) RMIStoppingCondition(org.evosuite.ga.stoppingconditions.RMIStoppingCondition) GlobalTimeStoppingCondition(org.evosuite.ga.stoppingconditions.GlobalTimeStoppingCondition)

Example 30 with Signal

use of sun.misc.Signal in project orientdb by orientechnologies.

the class OHazelcastPlugin method startup.

@Override
public void startup() {
    if (!enabled)
        return;
    Orient.instance().setRunningDistributed(true);
    OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(Integer.MAX_VALUE);
    OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.setValue(Integer.MAX_VALUE);
    OGlobalConfiguration.STORAGE_TRACK_CHANGED_RECORDS_IN_WAL.setValue(true);
    // REGISTER TEMPORARY USER FOR REPLICATION PURPOSE
    serverInstance.addTemporaryUser(REPLICATOR_USER, "" + new SecureRandom().nextLong(), "*");
    super.startup();
    status = NODE_STATUS.STARTING;
    final String localNodeName = nodeName;
    activeNodes.clear();
    activeNodesNamesByUuid.clear();
    activeNodesUuidByName.clear();
    // CLOSE ALL CONNECTIONS TO THE SERVERS
    for (ORemoteServerController server : remoteServers.values()) server.close();
    remoteServers.clear();
    registeredNodeById.clear();
    registeredNodeByName.clear();
    try {
        hazelcastInstance = configureHazelcast();
        nodeUuid = hazelcastInstance.getCluster().getLocalMember().getUuid();
        final LifecycleService lifecycleService = hazelcastInstance.getLifecycleService();
        lifecycleService.addLifecycleListener(this);
        OLogManager.instance().info(this, "Starting distributed server '%s' (hzID=%s)...", localNodeName, nodeUuid);
        final long clusterTime = getClusterTime();
        final long deltaTime = System.currentTimeMillis() - clusterTime;
        OLogManager.instance().info(this, "Distributed cluster time=%s (delta from local node=%d)...", new Date(clusterTime), deltaTime);
        activeNodes.put(localNodeName, hazelcastInstance.getCluster().getLocalMember());
        activeNodesNamesByUuid.put(nodeUuid, localNodeName);
        activeNodesUuidByName.put(localNodeName, nodeUuid);
        configurationMap = new OHazelcastDistributedMap(this, hazelcastInstance);
        OServer.registerServerInstance(localNodeName, serverInstance);
        initRegisteredNodeIds();
        // PUBLISH CURRENT NODE NAME
        final ODocument nodeCfg = new ODocument();
        nodeCfg.setTrackingChanges(false);
        // REMOVE ANY PREVIOUS REGISTERED SERVER WITH THE SAME NODE NAME
        final Set<String> node2Remove = new HashSet<String>();
        for (Iterator<Map.Entry<String, Object>> it = configurationMap.getHazelcastMap().entrySet().iterator(); it.hasNext(); ) {
            final Map.Entry<String, Object> entry = it.next();
            if (entry.getKey().startsWith(CONFIG_NODE_PREFIX)) {
                final ODocument nCfg = (ODocument) entry.getValue();
                if (nodeName.equals(nCfg.field("name"))) {
                    // SAME NODE NAME: REMOVE IT
                    node2Remove.add(entry.getKey());
                }
            }
        }
        for (String n : node2Remove) configurationMap.getHazelcastMap().remove(n);
        nodeCfg.field("id", nodeId);
        nodeCfg.field("uuid", nodeUuid);
        nodeCfg.field("name", nodeName);
        ORecordInternal.setRecordSerializer(nodeCfg, ODatabaseDocumentTx.getDefaultSerializer());
        configurationMap.put(CONFIG_NODE_PREFIX + nodeUuid, nodeCfg);
        // REGISTER CURRENT NODES
        for (Member m : hazelcastInstance.getCluster().getMembers()) {
            if (!m.getUuid().equals(nodeUuid)) {
                boolean found = false;
                for (int retry = 0; retry < 10; ++retry) {
                    final String memberName = getNodeName(m, false);
                    if (memberName == null || memberName.startsWith("ext:")) {
                        // ACTIVE NODE IN HZ, BUT NOT YET REGISTERED, WAIT AND RETRY
                        Thread.sleep(1000);
                        continue;
                    }
                    found = true;
                    activeNodes.put(memberName, m);
                    activeNodesNamesByUuid.put(m.getUuid(), memberName);
                    activeNodesUuidByName.put(memberName, m.getUuid());
                    break;
                }
                if (!found)
                    ODistributedServerLog.warn(this, localNodeName, null, DIRECTION.NONE, "Cannot find configuration for member: %s, uuid", m, m.getUuid());
            }
        }
        assignLockManagerFromCluster();
        messageService = new ODistributedMessageServiceImpl(this);
        initSystemDatabase();
        ODistributedServerLog.info(this, localNodeName, null, DIRECTION.NONE, "Servers in cluster: %s", activeNodes.keySet());
        publishLocalNodeConfiguration();
        if (!configurationMap.containsKey(CONFIG_NODE_PREFIX + nodeUuid)) {
            // NODE NOT REGISTERED, FORCING SHUTTING DOWN
            ODistributedServerLog.error(this, localNodeName, null, DIRECTION.NONE, "Error on registering local node on cluster");
            throw new ODistributedStartupException("Error on registering local node on cluster");
        }
        // CONNECTS TO ALL THE AVAILABLE NODES
        for (String m : activeNodes.keySet()) if (!m.equals(nodeName))
            getRemoteServer(m);
        publishLocalNodeConfiguration();
        installNewDatabasesFromCluster();
        loadLocalDatabases();
        membershipListenerMapRegistration = configurationMap.getHazelcastMap().addEntryListener(this, true);
        membershipListenerRegistration = hazelcastInstance.getCluster().addMembershipListener(this);
        // REGISTER CURRENT MEMBERS
        setNodeStatus(NODE_STATUS.ONLINE);
        publishLocalNodeConfiguration();
        final long delay = OGlobalConfiguration.DISTRIBUTED_PUBLISH_NODE_STATUS_EVERY.getValueAsLong();
        if (delay > 0) {
            publishLocalNodeConfigurationTask = new TimerTask() {

                @Override
                public void run() {
                    publishLocalNodeConfiguration();
                }
            };
            Orient.instance().scheduleTask(publishLocalNodeConfigurationTask, delay, delay);
        }
        final long statsDelay = OGlobalConfiguration.DISTRIBUTED_DUMP_STATS_EVERY.getValueAsLong();
        if (statsDelay > 0) {
            haStatsTask = new TimerTask() {

                @Override
                public void run() {
                    dumpStats();
                }
            };
            Orient.instance().scheduleTask(haStatsTask, statsDelay, statsDelay);
        }
        final long healthChecker = OGlobalConfiguration.DISTRIBUTED_CHECK_HEALTH_EVERY.getValueAsLong();
        if (healthChecker > 0) {
            healthCheckerTask = new OClusterHealthChecker(this);
            Orient.instance().scheduleTask(healthCheckerTask, healthChecker, healthChecker);
        }
        for (OServerNetworkListener nl : serverInstance.getNetworkListeners()) nl.registerBeforeConnectNetworkEventListener(this);
        // WAIT ALL THE MESSAGES IN QUEUE ARE PROCESSED OR MAX 10 SECONDS
        waitStartupIsCompleted();
        signalListener = new OSignalHandler.OSignalListener() {

            @Override
            public void onSignal(final Signal signal) {
                if (signal.toString().trim().equalsIgnoreCase("SIGTRAP"))
                    dumpStats();
            }
        };
        Orient.instance().getSignalHandler().registerListener(signalListener);
    } catch (Exception e) {
        ODistributedServerLog.error(this, localNodeName, null, DIRECTION.NONE, "Error on starting distributed plugin", e);
        throw OException.wrapException(new ODistributedStartupException("Error on starting distributed plugin"), e);
    }
    dumpServersStatus();
}
Also used : Signal(sun.misc.Signal) OServerNetworkListener(com.orientechnologies.orient.server.network.OServerNetworkListener) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) SecureRandom(java.security.SecureRandom) OException(com.orientechnologies.common.exception.OException) OInterruptedException(com.orientechnologies.common.concur.lock.OInterruptedException) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) IOException(java.io.IOException) OOfflineNodeException(com.orientechnologies.common.concur.OOfflineNodeException) FileNotFoundException(java.io.FileNotFoundException) OSignalHandler(com.orientechnologies.orient.core.OSignalHandler)

Aggregations

Signal (sun.misc.Signal)37 SignalHandler (sun.misc.SignalHandler)15 Test (org.junit.Test)8 IOException (java.io.IOException)4 BatchSearchLoop (org.icij.datashare.tasks.BatchSearchLoop)4 ReporterConfiguration (com.uber.jaeger.Configuration.ReporterConfiguration)2 SamplerConfiguration (com.uber.jaeger.Configuration.SamplerConfiguration)2 ConstSampler (com.uber.jaeger.samplers.ConstSampler)2 FinishCheck (com.vip.saturn.it.base.FinishCheck)2 LongtimeJavaJob (com.vip.saturn.it.job.LongtimeJavaJob)2 JobConfig (com.vip.saturn.job.console.domain.JobConfig)2 ActiveSpan (io.opentracing.ActiveSpan)2 GlobalTracer (io.opentracing.util.GlobalTracer)2 BufferedReader (java.io.BufferedReader)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 Path (java.nio.file.Path)2 Paths (java.nio.file.Paths)2