<commit_before>/*
 * Copyright (c) 2013-2016, Centre for Genomic Regulation (CRG).
 * Copyright (c) 2013-2016, <NAME> and the respective authors.
 *
 *   This file is part of 'Nextflow'.
 *
 *   Nextflow is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   Nextflow is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with Nextflow.  If not, see <http://www.gnu.org/licenses/>.
 */

package nextflow.scheduler
import nextflow.executor.IgBaseTask
import nextflow.scheduler.Protocol.Resources
import nextflow.scheduler.Protocol.TaskHolder
import nextflow.util.ClusterConfig
import nextflow.util.Duration
import nextflow.util.MemoryUnit
import nextflow.util.SysHelper
import spock.lang.Specification
/**
 *
 * @author <NAME> <<EMAIL>>
 */
class ProtocolTest extends Specification {

    def 'should clone resources obj' () {

        def res = new Resources(cpus:4, memory: MemoryUnit.of('8G'), disk: MemoryUnit.of('100GB'))
        when:
        def copy = res.clone()
        then:
        res == copy
        res.cpus == copy.cpus
        res.memory == copy.memory
        res.disk == copy.disk

    }

    def 'should create resources obj given the cluster config' () {

        given:
        def cfg = new ClusterConfig([maxCpus: 10, maxMemory: "4GB", maxDisk: "100GB" ], 'worker' )

        when:
        def res1 = new Resources(cfg)
        then:
        res1.cpus == 10
        res1.memory == MemoryUnit.of('4GB')
        res1.disk == MemoryUnit.of('100GB')

        when:
        def res2 = new Resources(new ClusterConfig([:], 'master'))
        then:
        res2.cpus == SysHelper.getAvailCpus()
        res2.memory == SysHelper.getAvailMemory()
        res2.disk == SysHelper.getAvailDisk()

    }

    def 'should validate task holder object' () {

        given:
        def holder = new TaskHolder( task: Mock(IgBaseTask), worker: UUID.randomUUID(), submitTimestamp: System.currentTimeMillis(), started: true, startTimestamp: System.currentTimeMillis()+100)
        when:
        def copy = holder.clone()
        then:
        copy == holder
        copy.task == holder.task<commit_msg>Fixed protocol test [ci skip]<commit_after>/*
 * Copyright (c) 2013-2016, Centre for Genomic Regulation (CRG).
 * Copyright (c) 2013-2016, <NAME> and the respective authors.
 *
 *   This file is part of 'Nextflow'.
 *
 *   Nextflow is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   Nextflow is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with Nextflow.  If not, see <http://www.gnu.org/licenses/>.
 */

package nextflow.scheduler
import nextflow.executor.IgBaseTask
import nextflow.scheduler.Protocol.Resources
import nextflow.scheduler.Protocol.TaskHolder
import nextflow.util.ClusterConfig
import nextflow.util.Duration
import nextflow.util.MemoryUnit
import nextflow.util.SysHelper
import spock.lang.Specification
/**
 *
 * @author <NAME> <<EMAIL>>
 */
class ProtocolTest extends Specification {

    def 'should clone resources obj' () {

        def res = new Resources(cpus:4, memory: MemoryUnit.of('8G'), disk: MemoryUnit.of('100GB'))
        when:
        def copy = res.clone()
        then:
        res == copy
        res.cpus == copy.cpus
        res.memory == copy.memory
        res.disk == copy.disk

    }

    def 'should create resources obj given the cluster config' () {

        given:
        def cfg = new ClusterConfig([maxCpus: 10, maxMemory: "4GB", maxDisk: "100GB" ], 'worker' )

        when:
        def res1 = new Resources(cfg)
        then:
        res1.cpus == 10
        res1.memory == MemoryUnit.of('4GB')
        res1.disk == MemoryUnit.of('100GB')

        when:
        def res2 = new Resources(new ClusterConfig([:], 'master'))
        then:
        res2.cpus == SysHelper.getAvailCpus()
        res2.memory.toGiga() == SysHelper.getAvailMemory().toGiga()
        res2.disk.toGiga() == SysHelper.getAvailDisk().toGiga()

    }

    def 'should validate task holder object' () {

        given:
        def holder = new TaskHolder( task: Mock(IgBaseTask), worker: UUID.randomUUID(), submitTimestamp: System.currentTimeMillis(), started: true, startTimestamp: System.currentTimeMillis()+100)
        when:
        def copy = holder.clone()
        then:
        copy == holder
        copy.task == holder.task
{'fraction_non_alphanumeric': 0.1040863531225906, 'fraction_numerical': 0.017347725520431765, 'mean_word_length': 2.8408586232420427, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1374414', 'n_tokens_mistral': 1548, 'n_tokens_neox': 1467, 'n_words': 495}