/*
 * The MIT License (MIT)
 * 
 * Copyright (c) 2013-2014 Jeff Nelson, Cinchapi Software Collective
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.cinchapi.concourse.server.storage;

import java.io.File;

import org.cinchapi.concourse.server.io.FileSystem;
import org.cinchapi.concourse.time.Time;
import org.cinchapi.concourse.util.TestData;
import org.junit.Rule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;

/**
 * Unit tests for {@link Transaction}.
 * 
 * @author jnelson
 */
public class TransactionTest extends AtomicOperationTest {

    private String directory;

    @Rule
    public TestWatcher w = new TestWatcher() {
        @Override
        protected void starting(Description desc) {
            store.stop(); // Stop the engine so that data isn't transported in
                          // the middle of a test.
        }
    };

    @Override
    protected void cleanup(Store store) {
        FileSystem.deleteDirectory(directory);
    }

    @Override
    protected Engine getDestination() {
        directory = TestData.DATA_DIR + File.separator + Time.now();
        Engine engine = new Engine(directory + File.separator + "buffer",
                directory + File.separator + "database");
        engine.start(); // Start the engine manually because
                        // AtomicOperation#start does not do it
        return engine;
    }

    @Override
    protected Transaction getStore() {
        destination = getDestination();
        return Transaction.start((Engine) destination);
    }

}

@@ -1332,85 +1332,329 @@
 rse.
-time.Time;%0Aimport org.cinchapi.concourse.util.TestData;%0Aimport org.junit.Rule
+server.storage.temp.Write;%0Aimport org.cinchapi.concourse.testing.Variables;%0Aimport org.cinchapi.concourse.thrift.TObject;%0Aimport org.cinchapi.concourse.time.Time;%0Aimport org.cinchapi.concourse.util.Convert;%0Aimport org.cinchapi.concourse.util.TestData;%0Aimport org.junit.Assert;%0Aimport org.junit.Rule;%0Aimport org.junit.Test
 ;%0Aim
@@ -2837,10 +2837,764 @@
 %0A    %7D%0A%0A
+    @Test(expected = TransactionStateException.class)%0A    public void testNoChangesPersistOnFailure() %7B%0A        super.testNoChangesPersistOnFailure();%0A    %7D%0A%0A    @Test(expected = TransactionStateException.class)%0A    public void testCommitFailsIfVersionChanges() %7B%0A        super.testCommitFailsIfVersionChanges();%0A    %7D%0A%0A    @Test(expected = TransactionStateException.class)%0A    public void testFailureIfWriteToRecordThatIsRead()%0A            throws InterruptedException %7B%0A        super.testFailureIfWriteToRecordThatIsRead();%0A    %7D%0A%0A    @Test(expected = TransactionStateException.class)%0A    public void testFailureIfWriteToKeyInRecordThatIsRead()%0A            throws InterruptedException %7B%0A        super.testFailureIfWriteToKeyInRecordThatIsRead();%0A    %7D%0A%0A
 %7D%0A

fix failing test