<commit_before>package brooklyn.policy.loadbalancing

import static brooklyn.test.TestUtils.*
import static java.util.concurrent.TimeUnit.*
import static org.testng.Assert.*

import java.io.ByteArrayOutputStream
import java.io.PrintStream

import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.testng.annotations.Test

import brooklyn.entity.Application
import brooklyn.entity.Entity
import brooklyn.test.entity.TestApplication

public class LoadBalancingPolicySoakTest extends AbstractLoadBalancingPolicyTest {

    protected static final Logger LOG = LoggerFactory.getLogger(LoadBalancingPolicySoakTest.class)
    
    private static final long TIMEOUT_MS = 40*1000;
    
    @Test
    public void testLoadBalancingQuickTest() {
        RunConfig config = new RunConfig()
        config.numCycles = 1
        config.numContainers = 5
        config.numItems = 5
        config.lowThreshold = 200
        config.highThreshold = 300
        config.totalRate = config.numContainers*(0.95*config.highThreshold)
    
        runLoadBalancingSoakTest(config)
    }
    
    @Test
    public void testLoadBalancingManyItemsQuickTest() {
        RunConfig config = new RunConfig()
        config.numCycles = 1
        config.numContainers = 5
        config.numItems = 30
        config.lowThreshold = 200
        config.highThreshold = 300
        config.numContainerStopsPerCycle = 1
        config.numItemStopsPerCycle = 1
        config.totalRate = config.numContainers*(0.95*config.highThreshold)
    
        runLoadBalancingSoakTest(config)
    }
    
    @Test(groups="Acceptance") // acceptance group, because it's slow to run many cycles
    public void testLoadBalancingSoakTest() {
        RunConfig config = new RunConfig()
        config.numCycles = 100
        config.numContainers = 5
        config.numItems = 5
        config.lowThreshold = 200
        config.highThreshold = 300
        config.totalRate = config.numContainers*(0.95*config.highThreshold)
    
        runLoadBalancingSoakTest(config)
    }

    @Test(groups="Acceptance") // acceptance group, because it's slow to run many cycles
    public void testLoadBalancingManyItemsSoakTest() {
        RunConfig config = new RunConfig()
        config.numCycles = 100
        config.numContainers = 5
        config.numItems = 30
        config.lowThreshold = 200
        config.highThreshold = 300
        config.totalRate = config.numContainers*(0.95*config.highThreshold)
        config.numContainerStopsPerCycle = 3
        config.numItemStopsPerCycle = 10
        
        runLoadBalancingSoakTest(config)
    }

    // FIXME code is too inefficient; doesn't balance 1000 items within the timeout period.
    // And that's with only one workrate report per item per cycle, rather than every 500ms!
    @Test(groups="Acceptance")
    public void testLoadBalancingManyManyItemsTest() {
        RunConfig config = new RunConfig()
        config.numCycles = 1
        config.numContainers = 5
        config.numItems = 1000
        config.lowThreshold = 2000
        config.highThreshold = 3000
        config.numContainerStopsPerCycle = 0
        config.numItemStopsPerCycle = 0
        config.totalRate = config.numContainers*(0.95*config.highThreshold)
        config.verbose = false
        
        runLoadBalancingSoakTest(config)
    }
    
    private void runLoadBalancingSoakTest(RunConfig config) {
        int numCycles = config.numCycles
        int numContainers = config.numContainers
        int numItems = config.numItems
        double lowThreshold = config.lowThreshold
        double highThreshold = config.highThreshold
        int totalRate = config.totalRate
        int numContainerStopsPerCycle = config.numContainerStopsPerCycle
        int numItemStopsPerCycle = config.numItemStopsPerCycle
        boolean verbose = config.verbose
        
        MockItemEntity.totalMoveCount.set(0)
        
        List<MockContainerEntity> containers = new ArrayList<MockContainerEntity>()
        List<MockItemEntity> items = new ArrayList<MockItemEntity>()
        <commit_msg>LoadBalancingPolicySoakTest: mark slow tests as "Integration" rather than "Acceptance"<commit_after>package brooklyn.policy.loadbalancing

import static brooklyn.test.TestUtils.*
import static java.util.concurrent.TimeUnit.*
import static org.testng.Assert.*

import java.io.ByteArrayOutputStream
import java.io.PrintStream

import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.testng.annotations.Test

import brooklyn.entity.Application
import brooklyn.entity.Entity
import brooklyn.test.entity.TestApplication

public class LoadBalancingPolicySoakTest extends AbstractLoadBalancingPolicyTest {

    protected static final Logger LOG = LoggerFactory.getLogger(LoadBalancingPolicySoakTest.class)
    
    private static final long TIMEOUT_MS = 40*1000;
    
    @Test
    public void testLoadBalancingQuickTest() {
        RunConfig config = new RunConfig()
        config.numCycles = 1
        config.numContainers = 5
        config.numItems = 5
        config.lowThreshold = 200
        config.highThreshold = 300
        config.totalRate = config.numContainers*(0.95*config.highThreshold)
    
        runLoadBalancingSoakTest(config)
    }
    
    @Test
    public void testLoadBalancingManyItemsQuickTest() {
        RunConfig config = new RunConfig()
        config.numCycles = 1
        config.numContainers = 5
        config.numItems = 30
        config.lowThreshold = 200
        config.highThreshold = 300
        config.numContainerStopsPerCycle = 1
        config.numItemStopsPerCycle = 1
        config.totalRate = config.numContainers*(0.95*config.highThreshold)
    
        runLoadBalancingSoakTest(config)
    }
    
    @Test(groups="Integration") // acceptance group, because it's slow to run many cycles
    public void testLoadBalancingSoakTest() {
        RunConfig config = new RunConfig()
        config.numCycles = 100
        config.numContainers = 5
        config.numItems = 5
        config.lowThreshold = 200
        config.highThreshold = 300
        config.totalRate = config.numContainers*(0.95*config.highThreshold)
    
        runLoadBalancingSoakTest(config)
    }

    @Test(groups="Integration") // acceptance group, because it's slow to run many cycles
    public void testLoadBalancingManyItemsSoakTest() {
        RunConfig config = new RunConfig()
        config.numCycles = 100
        config.numContainers = 5
        config.numItems = 30
        config.lowThreshold = 200
        config.highThreshold = 300
        config.totalRate = config.numContainers*(0.95*config.highThreshold)
        config.numContainerStopsPerCycle = 3
        config.numItemStopsPerCycle = 10
        
        runLoadBalancingSoakTest(config)
    }

    // FIXME code is too inefficient; doesn't balance 1000 items within the timeout period.
    // And that's with only one workrate report per item per cycle, rather than every 500ms!
    @Test(groups="Integration")
    public void testLoadBalancingManyManyItemsTest() {
        RunConfig config = new RunConfig()
        config.numCycles = 1
        config.numContainers = 5
        config.numItems = 1000
        config.lowThreshold = 2000
        config.highThreshold = 3000
        config.numContainerStopsPerCycle = 0
        config.numItemStopsPerCycle = 0
        config.totalRate = config.numContainers*(0.95*config.highThreshold)
        config.verbose = false
        
        runLoadBalancingSoakTest(config)
    }
    
    private void runLoadBalancingSoakTest(RunConfig config) {
        int numCycles = config.numCycles
        int numContainers = config.numContainers
        int numItems = config.numItems
        double lowThreshold = config.lowThreshold
        double highThreshold = config.highThreshold
        int totalRate = config.totalRate
        int numContainerStopsPerCycle = config.numContainerStopsPerCycle
        int numItemStopsPerCycle = config.numItemStopsPerCycle
        boolean verbose = config.verbose
        
        MockItemEntity.totalMoveCount.set(0)
        
        List<MockContainerEntity> containers = new ArrayList<MockContainerEntity>()
        List<MockItemEntity> items = new ArrayList<MockItemEntity>()
        
{'fraction_non_alphanumeric': 0.06764634442555259, 'fraction_numerical': 0.02283215933932475, 'mean_word_length': 2.839160839160839, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1922752', 'n_tokens_mistral': 2408, 'n_tokens_neox': 2217, 'n_words': 506}