<commit_before>package org.dasein.cloud.test.compute;

import org.dasein.cloud.CloudException;
import org.dasein.cloud.InternalException;
import org.dasein.cloud.OperationNotSupportedException;
import org.dasein.cloud.Requirement;
import org.dasein.cloud.compute.ComputeServices;
import org.dasein.cloud.compute.Snapshot;
import org.dasein.cloud.compute.SnapshotCreateOptions;
import org.dasein.cloud.compute.SnapshotFilterOptions;
import org.dasein.cloud.compute.SnapshotState;
import org.dasein.cloud.compute.SnapshotSupport;
import org.dasein.cloud.compute.VirtualMachine;
import org.dasein.cloud.compute.VmState;
import org.dasein.cloud.compute.VolumeSupport;
import org.dasein.cloud.dc.Region;
import org.dasein.cloud.test.DaseinTestManager;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;

import static org.junit.Assert.*;
import static org.junit.Assume.assumeTrue;

/**
 * Tests of stateful functions in Dasein Cloud snapshot management support.
 * <p>Created by <NAME>: 2/27/13 8:25 AM</p>
 * @author <NAME>
 * @version 2013.04 initial version
 * @since 2013.04
 */
public class StatefulSnapshotTests {
    static private DaseinTestManager tm;

    @BeforeClass
    static public void configure() {
        tm = new DaseinTestManager(StatelessSnapshotTests.class);
    }

    @AfterClass
    static public void cleanUp() {
        if( tm != null ) {
            tm.close();
        }
    }

    @Rule
    public final TestName name = new TestName();

    private String provisionedSnapshotId;

    private String testShareAccount;
    private String testSnapshotId;
    private String testSourceRegion;
    private String testVolumeId;

    public StatefulSnapshotTests() { }

    @Before
    public void before() {
        tm.begin(name.getMethodName());
        assumeTrue(!tm.isTestSkipped());
        ComputeServices services = tm.getProvider().getComputeServices();
        SnapshotSupport support = null;

        if( services != null ) {
            support = services.getSnapshotSupport();
        }

        if( name.getMethodName().equals("createSnapshot") ) {
            testVolumeId = tm.getTestVolumeId(DaseinTestManager.STATEFUL, true, null, null);
            if( testVolumeId != null ) {
                if( support != null ) {
                    try {
                        if( support.identifyAttachmentRequirement().equals(Requirement.REQUIRED) ) {
                            String vmId = tm.getTestVMId(DaseinTestManager.STATEFUL, VmState.RUNNING, true, null);

                            if( vmId != null ) {
                                @SuppressWarnings("ConstantConditions") VirtualMachine vm = services.getVirtualMachineSupport().getVirtualMachine(vmId);

                                if( vm != null ) {
                                    VolumeSupport volumeSupport = services.getVolumeSupport();

                                    if( volumeSupport != null ) {
                                        for( String deviceId : volumeSupport.listPossibleDeviceIds(vm.getPlatform()) ) {
                                            try {
                                                volumeSupport.attach(testVolumeId, vmId, deviceId);
                                                break;
                                            }
                                            catch( Throwable ignore ) {
                                                // ignore
                                            }
                                        }
                                    }
                                }

                            }
                        }
                    }
                    catch( Throwable ignore ) {
                        // ignore
                    }
                }
            }
        }
        else if( name.getMethodName().equals("copySnapshot") ) {
            if( support != null ) {
                Snapshot sourceSnapshot = null;

                try {
                    for( Region r : tm.getProvider().getDataCenterServices().listRegions() ) {
                        //noinspection ConstantConditions
                        if( !r.getProviderRegionId().equals(tm.getContext().getRegionId()) ) {
                            for( Snapshot snapshot : support.listSnapshots() ) {
                                if( snapshot.getCurrentState().equals(SnapshotState.AVAILABLE) ) {
                                    sourceSnapshot = snapshot;
                                    break;
                                }
                            }
                        }
                    }
                }
                catch( Throwable ignore ) {
                    // ignore
                }
                if( sourceSnapshot != null ) {
                    testSnapshotId = sourceSnapshot.getProviderSnapshotId();
                    testSourceRegion = sourceSnapshot.getRegionId();
                }
            }
        }
        else if( name.getMethodName().equals("filterSnapshot") ) {
            if( support != null ) {
                try {
                    testSnapshotId = DaseinTestManager.getComputeResources().provisionSnapshot(support, "filter", "dsnfilter", null);
                }
                catch( Throwable t ) {
                    tm.warn("Failed to provision VM for filter test: " + t.getMessage());
                }
            }
        }
        else if( name.getMethodName().equals("removeSnapshot") ) {
            testSnapshotId = tm.getTestSnapshotId(DaseinTestManager.REMOVED, true);
        }
        else {
            testSnapshotId = tm.getTestSnapshotId(DaseinTestManager.STATEFUL, true);
            testShareAccount = System.getProperty("shareAccount");
            if( name.getMethodName().equals("addPrivateShare") || name.getMethodName().equals("addPublicShare") ||
                    name.getMethodName().equals("removePrivateShare") || name.getMethodName().equals("removePublicShare") || name.getMethodName().equals("removeAllShares") ) {
<commit_msg>Fixed a couple of bugs in the snapshot tests<commit_after>package org.dasein.cloud.test.compute;

import org.dasein.cloud.CloudException;
import org.dasein.cloud.InternalException;
import org.dasein.cloud.OperationNotSupportedException;
import org.dasein.cloud.Requirement;
import org.dasein.cloud.compute.ComputeServices;
import org.dasein.cloud.compute.Snapshot;
import org.dasein.cloud.compute.SnapshotCreateOptions;
import org.dasein.cloud.compute.SnapshotFilterOptions;
import org.dasein.cloud.compute.SnapshotState;
import org.dasein.cloud.compute.SnapshotSupport;
import org.dasein.cloud.compute.VirtualMachine;
import org.dasein.cloud.compute.VmState;
import org.dasein.cloud.compute.VolumeSupport;
import org.dasein.cloud.dc.Region;
import org.dasein.cloud.test.DaseinTestManager;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;

import static org.junit.Assert.*;
import static org.junit.Assume.assumeTrue;

/**
 * Tests of stateful functions in Dasein Cloud snapshot management support.
 * <p>Created by <NAME>: 2/27/13 8:25 AM</p>
 * @author <NAME>
 * @version 2013.04 initial version
 * @since 2013.04
 */
public class StatefulSnapshotTests {
    static private DaseinTestManager tm;

    @BeforeClass
    static public void configure() {
        tm = new DaseinTestManager(StatefulSnapshotTests.class);
    }

    @AfterClass
    static public void cleanUp() {
        if( tm != null ) {
            tm.close();
        }
    }

    @Rule
    public final TestName name = new TestName();

    private String provisionedSnapshotId;

    private String testShareAccount;
    private String testSnapshotId;
    private String testSourceRegion;
    private String testVolumeId;

    public StatefulSnapshotTests() { }

    @Before
    public void before() {
        tm.begin(name.getMethodName());
        assumeTrue(!tm.isTestSkipped());
        ComputeServices services = tm.getProvider().getComputeServices();
        SnapshotSupport support = null;

        if( services != null ) {
            support = services.getSnapshotSupport();
        }

        if( name.getMethodName().equals("createSnapshot") ) {
            testVolumeId = tm.getTestVolumeId(DaseinTestManager.STATEFUL, true, null, null);
            if( testVolumeId != null ) {
                if( support != null ) {
                    try {
                        if( support.identifyAttachmentRequirement().equals(Requirement.REQUIRED) ) {
                            String vmId = tm.getTestVMId(DaseinTestManager.STATEFUL, VmState.RUNNING, true, null);

                            if( vmId != null ) {
                                @SuppressWarnings("ConstantConditions") VirtualMachine vm = services.getVirtualMachineSupport().getVirtualMachine(vmId);

                                if( vm != null ) {
                                    VolumeSupport volumeSupport = services.getVolumeSupport();

                                    if( volumeSupport != null ) {
                                        for( String deviceId : volumeSupport.listPossibleDeviceIds(vm.getPlatform()) ) {
                                            try {
                                                volumeSupport.attach(testVolumeId, vmId, deviceId);
                                                break;
                                            }
                                            catch( Throwable ignore ) {
                                                // ignore
                                            }
                                        }
                                    }
                                }

                            }
                        }
                    }
                    catch( Throwable ignore ) {
                        // ignore
                    }
                }
            }
        }
        else if( name.getMethodName().equals("copySnapshot") ) {
            if( support != null ) {
                Snapshot sourceSnapshot = null;

                try {
                    for( Region r : tm.getProvider().getDataCenterServices().listRegions() ) {
                        //noinspection ConstantConditions
                        if( !r.getProviderRegionId().equals(tm.getContext().getRegionId()) ) {
                            for( Snapshot snapshot : support.listSnapshots() ) {
                                if( snapshot.getCurrentState().equals(SnapshotState.AVAILABLE) ) {
                                    sourceSnapshot = snapshot;
                                    break;
                                }
                            }
                        }
                    }
                }
                catch( Throwable ignore ) {
                    // ignore
                }
                if( sourceSnapshot != null ) {
                    testSnapshotId = sourceSnapshot.getProviderSnapshotId();
                    testSourceRegion = sourceSnapshot.getRegionId();
                }
            }
        }
        else if( name.getMethodName().equals("filterSnapshots") ) {
            if( support != null ) {
                try {
                    testSnapshotId = DaseinTestManager.getComputeResources().provisionSnapshot(support, "filter", "dsnfilter", null);
                }
                catch( Throwable t ) {
                    tm.warn("Failed to provision VM for filter test: " + t.getMessage());
                }
            }
        }
        else if( name.getMethodName().equals("removeSnapshot") ) {
            testSnapshotId = tm.getTestSnapshotId(DaseinTestManager.REMOVED, true);
        }
        else {
            testSnapshotId = tm.getTestSnapshotId(DaseinTestManager.STATEFUL, true);
            testShareAccount = System.getProperty("shareAccount");
            if( name.getMethodName().equals("addPrivateShare") || name.getMethodName().equals("addPublicShare") ||
                    name.getMethodName().equals("removePrivateShare") || name.getMethodName().equals("removePublicShare") || name.getMethodName().equals("removeAllShares") ) {

{'fraction_non_alphanumeric': 0.09311708222383604, 'fraction_numerical': 0.0032276284999596546, 'mean_word_length': 1.5413163830223497, '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': 48, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4265400', 'n_tokens_mistral': 3017, 'n_tokens_neox': 2914, 'n_words': 558}