/**
 * Copyright (c) 2002-2011 "Neo Technology,"
 * Network Engine for Objects in Lund AB [http://neotechnology.com]
 *
 * This file is part of Neo4j.
 *
 * Neo4j is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package slavetest;

import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.neo4j.com.Protocol;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.helpers.Pair;
import org.neo4j.kernel.HighlyAvailableGraphDatabase;
import org.neo4j.kernel.ha.AbstractBroker;
import org.neo4j.kernel.ha.Broker;
import org.neo4j.kernel.ha.Master;
import org.neo4j.kernel.ha.MasterClient;
import org.neo4j.kernel.ha.MasterImpl;
import org.neo4j.kernel.ha.zookeeper.Machine;

public class SingleJvmWithNettyTest extends SingleJvmTest
{
    @Test
    public void assertThatNettyIsUsed() throws Exception
    {
        initializeDbs( 1 );
        assertTrue(
                "Slave Broker is not a client",
                ( (HighlyAvailableGraphDatabase) getSlave( 0 ) ).getBroker().getMaster().first() instanceof MasterClient );
    }

    @Override
    protected Broker makeSlaveBroker( MasterImpl master, int masterId, int id, GraphDatabaseService graphDb )
    {
        final Machine masterMachine = new Machine( masterId, -1, 1, -1,
                "localhost:" + Protocol.PORT );
        final Master client = new MasterClient( masterMachine, graphDb );
        return new AbstractBroker( id, graphDb )
        {
            public boolean iAmMaster()
            {
                return false;
            }

            public Pair<Master, Machine> getMasterReally()
            {
                return getMaster();
            }

            public Pair<Master, Machine> getMaster()
            {
                return Pair.of( client, masterMachine );
            }

            public Object instantiateMasterServer( GraphDatabaseService graphDb )
            {
                throw new UnsupportedOperationException(
                        "cannot instantiate master server on slave" );
            }
        };
    }
}

@@ -867,20 +867,189 @@
 t.assert
-True
+Equals;%0Aimport static org.junit.Assert.assertTrue;%0A%0Aimport java.io.BufferedReader;%0Aimport java.io.File;%0Aimport java.io.FileReader;%0Aimport java.util.concurrent.CountDownLatch
 ;%0A%0Aimpor
@@ -1144,16 +1144,54 @@
 ervice;%0A
+import org.neo4j.graphdb.Transaction;%0A
 import o
@@ -2849,16 +2849,16 @@
       %7D%0A
-
         
@@ -2865,11 +2865,1755 @@
 %7D;%0A    %7D
+%0A%0A    @Test%0A    public void makeSureLogMessagesIsWrittenEvenAfterInternalRestart() throws Exception%0A    %7B%0A        initializeDbs( 1 );%0A        final CountDownLatch latch1 = new CountDownLatch( 1 );%0A        final GraphDatabaseService slave = getSlave( 0 );%0A        Thread t1 = new Thread()%0A        %7B%0A            @Override%0A            public void run()%0A            %7B%0A                try%0A                %7B%0A                    Transaction tx = slave.beginTx();%0A                    slave.createNode();%0A                    latch1.await();%0A                    tx.success();%0A                    tx.finish();%0A                %7D%0A                catch ( InterruptedException e )%0A                %7B%0A                    throw new RuntimeException( e );%0A                %7D%0A            %7D%0A        %7D;%0A        t1.start();%0A%0A        Thread t2 = new Thread()%0A        %7B%0A            @Override%0A            public void run()%0A            %7B%0A                Transaction tx = slave.beginTx();%0A                slave.createNode();%0A                latch1.countDown();%0A                tx.success();%0A                tx.finish();%0A            %7D%0A        %7D;%0A        t2.start();%0A        %0A        t1.join();%0A        t2.join();%0A        %0A        assertEquals( 2, countOccurences( %22Opened a new channel%22, new File( dbPath( 1 ), %22messages.log%22 ) ) );%0A    %7D%0A%0A    private int countOccurences( String string, File file ) throws Exception%0A    %7B%0A        BufferedReader reader = new BufferedReader( new FileReader( file ) );%0A        String line = null;%0A        int counter = 0;%0A        while ( (line = reader.readLine()) != null )%0A        %7B%0A            System.out.println( line );%0A            if ( line.contains( string ) ) counter++;%0A        %7D%0A        reader.close();%0A        return counter;%0A    %7D
 %0A%7D%0A

Test for StringLogger internal reopen issue