Search in sources :

Example 56 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class CompiledJunctionInternalsJUnitTest method testOrganizedOperandsSingleRangeJunctionCreationWithNoIterOperandForOR.

/**
   * Tests the creation of a single RangeJunction if the CompiledJunction only contains same index
   * condition without iter operand for OR
   */
@Ignore
@Test
public void testOrganizedOperandsSingleRangeJunctionCreationWithNoIterOperandForOR() {
    LogWriter logger = CacheUtils.getLogger();
    try {
        CompiledComparison[] cv = null;
        ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache());
        this.bindIteratorsAndCreateIndex(context);
        cv = new CompiledComparison[12];
        cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(2)), OQLLexerTokenTypes.TOK_EQ);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(5)), OQLLexerTokenTypes.TOK_LE);
        cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_LT);
        cv[3] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GT);
        cv[4] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GE);
        cv[5] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_NE);
        cv[6] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(2)), OQLLexerTokenTypes.TOK_EQ);
        cv[7] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(5)), OQLLexerTokenTypes.TOK_LE);
        cv[8] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_LT);
        cv[9] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GT);
        cv[10] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GE);
        cv[11] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_NE);
        OrganizedOperands oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_or, cv, context);
        assertNotNull("OrganizedOperand object is null", oo);
        assertTrue("Filter Openad of OrganizedOperand is not of type CompiledJunction", oo.filterOperand instanceof RangeJunction);
        RangeJunction rj = (RangeJunction) oo.filterOperand;
        assertEquals(cv.length, rj.getOperands().size());
    } catch (Exception e) {
        logger.error(e);
        fail(e.toString());
    }
}
Also used : LogWriter(org.apache.geode.LogWriter) Ignore(org.junit.Ignore) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 57 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class CompiledJunctionInternalsJUnitTest method testOrganizedOperandsOfSingleRangeJunctionWithNoIterOperandForAND_2.

/**
   * Tests the functionality of organizedOperands function of a RangeJunction which is an AND with
   * no IterOperand but where the operator needs reflection. as the condition is Key > Path ( which
   * means Path less than Key) If the RangeJunction boils down toa single condition which can be
   * evalauted as a CompiledComparison then the filter operand will be a CompiledComparison
   * 
   */
@Test
public void testOrganizedOperandsOfSingleRangeJunctionWithNoIterOperandForAND_2() {
    LogWriter logger = CacheUtils.getCache().getLogger();
    try {
        CompiledComparison[] cv = null;
        ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache());
        this.bindIteratorsAndCreateIndex(context);
        cv = new CompiledComparison[3];
        cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_LT);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(5)), OQLLexerTokenTypes.TOK_LE);
        cv[2] = new CompiledComparison(new CompiledLiteral(new Integer(2)), new CompiledPath(new CompiledID("p"), "ID"), OQLLexerTokenTypes.TOK_GT);
        OrganizedOperands oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
        assertNotNull("OrganizedOperand object is null", oo);
        assertTrue("Filter Openad of OrganizedOperand is not of type RangeJunction", oo.filterOperand instanceof RangeJunction);
        RangeJunction rj = (RangeJunction) oo.filterOperand;
        assertEquals(cv.length, rj.getOperands().size());
        OrganizedOperands oo1 = rj.organizeOperands(context);
        assertNotNull(oo1);
        assertNull(oo1.iterateOperand);
        assertNotNull(oo1.filterOperand);
        assertEquals(oo1.filterOperand, cv[2]);
    } catch (Exception e) {
        logger.error(e);
        fail(e.toString());
    }
}
Also used : LogWriter(org.apache.geode.LogWriter) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 58 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class LocatorDUnitTest method testLocatorBecomesCoordinator.

/**
   * Tests starting one locator in a remote VM and having multiple members of the distributed system
   * join it. This ensures that members start up okay, and that handling of a stopped locator is
   * correct. It then restarts the locator to demonstrate that it can connect to and function as the
   * group coordinator
   */
@Test
public void testLocatorBecomesCoordinator() throws Exception {
    disconnectAllFromDS();
    final String expected = "java.net.ConnectException";
    final String addExpected = "<ExpectedException action=add>" + expected + "</ExpectedException>";
    final String removeExpected = "<ExpectedException action=remove>" + expected + "</ExpectedException>";
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    final int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    DistributedTestUtils.deleteLocatorStateFile(port1);
    final String locators = NetworkUtils.getServerHostName(host) + "[" + port + "]";
    vm0.invoke(getUniqueName() + 1, () -> startSBLocator(port));
    try {
        final Properties props = new Properties();
        props.setProperty(LOCATORS, locators);
        props.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "true");
        props.put(ENABLE_CLUSTER_CONFIGURATION, "false");
        addDSProps(props);
        vm1.invoke(() -> {
            DistributedSystem sys = getSystem(props);
            sys.getLogWriter().info(addExpected);
        });
        vm2.invoke(() -> {
            DistributedSystem sys = getSystem(props);
            sys.getLogWriter().info(addExpected);
        });
        system = (InternalDistributedSystem) getSystem(props);
        final DistributedMember coord = MembershipManagerHelper.getCoordinator(system);
        org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("coordinator before termination of locator is " + coord);
        vm0.invoke(() -> stopLocator());
        // now ensure that one of the remaining members became the coordinator
        Awaitility.waitAtMost(15000, TimeUnit.MILLISECONDS).pollInterval(200, TimeUnit.MILLISECONDS).until(() -> !coord.equals(MembershipManagerHelper.getCoordinator(system)));
        DistributedMember newCoord = MembershipManagerHelper.getCoordinator(system);
        LogWriterUtils.getLogWriter().info("coordinator after shutdown of locator was " + newCoord);
        if (newCoord == null || coord.equals(newCoord)) {
            fail("another member should have become coordinator after the locator was stopped: " + newCoord);
        }
        // restart the locator to demonstrate reconnection & make disconnects faster
        // it should also regain the role of coordinator, so we check to make sure
        // that the coordinator has changed
        vm0.invoke(getUniqueName() + "2", () -> startSBLocator(port));
        final DistributedMember tempCoord = newCoord;
        Awaitility.waitAtMost(5000, TimeUnit.MILLISECONDS).pollInterval(200, TimeUnit.MILLISECONDS).until(() -> !tempCoord.equals(MembershipManagerHelper.getCoordinator(system)));
        system.disconnect();
        LogWriter bgexecLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, System.out);
        bgexecLogger.info(removeExpected);
        SerializableRunnable disconnect = new SerializableRunnable("Disconnect from " + locators) {

            public void run() {
            }
        };
        vm1.invoke(() -> {
            DistributedSystem sys = InternalDistributedSystem.getAnyInstance();
            if (sys != null && sys.isConnected()) {
                sys.disconnect();
            }
            // connectExceptions occur during disconnect, so we need the
            // expectedexception hint to be in effect until this point
            LogWriter bLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, System.out);
            bLogger.info(removeExpected);
        });
        vm2.invoke(() -> {
            DistributedSystem sys = InternalDistributedSystem.getAnyInstance();
            if (sys != null && sys.isConnected()) {
                sys.disconnect();
            }
            // connectExceptions occur during disconnect, so we need the
            // expectedexception hint to be in effect until this point
            LogWriter bLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, System.out);
            bLogger.info(removeExpected);
        });
        vm0.invoke(() -> stopLocator());
    } finally {
        vm0.invoke(() -> stopLocator());
    }
}
Also used : LocalLogWriter(org.apache.geode.internal.logging.LocalLogWriter) InternalLogWriter(org.apache.geode.internal.logging.InternalLogWriter) LogWriter(org.apache.geode.LogWriter) VM(org.apache.geode.test.dunit.VM) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) Properties(java.util.Properties) LocalLogWriter(org.apache.geode.internal.logging.LocalLogWriter) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest)

Example 59 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class LocatorDUnitTest method testLeadAndCoordFailure.

/**
   * test lead member and coordinator failure with network partition detection enabled. It would be
   * nice for this test to have more than two "server" vms, to demonstrate that they all exit when
   * the leader and potential- coordinator both disappear in the loss-correlation-window, but there
   * are only four vms available for dunit testing.
   * <p>
   * So, we start two locators with admin distributed systems, then start two regular distributed
   * members.
   * <p>
   * We kill the second locator (which is not the view coordinator) and then kill the non-lead
   * member. That should be okay - the lead and remaining locator continue to run.
   * <p>
   * We then kill the lead member and demonstrate that the original locator (which is now the sole
   * remaining member) shuts itself down.
   */
@Test
public void testLeadAndCoordFailure() throws Exception {
    IgnoredException.addIgnoredException("Possible loss of quorum due");
    disconnectAllFromDS();
    Host host = Host.getHost(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    VM locvm = host.getVM(3);
    Locator locator = null;
    int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
    final int port1 = ports[0];
    this.port1 = port1;
    final int port2 = ports[1];
    DistributedTestUtils.deleteLocatorStateFile(port1, port2);
    final String host0 = NetworkUtils.getServerHostName(host);
    final String locators = host0 + "[" + port1 + "]," + host0 + "[" + port2 + "]";
    final Properties properties = new Properties();
    properties.put(MCAST_PORT, "0");
    properties.put(LOCATORS, locators);
    properties.put(ENABLE_NETWORK_PARTITION_DETECTION, "true");
    properties.put(DISABLE_AUTO_RECONNECT, "true");
    properties.put(MEMBER_TIMEOUT, "2000");
    properties.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
    // properties.put("log-level", "fine");
    properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
    addDSProps(properties);
    try {
        final String uname = getUniqueName();
        File logFile = new File("");
        locator = Locator.startLocatorAndDS(port1, logFile, properties);
        final DistributedSystem sys = locator.getDistributedSystem();
        sys.getLogWriter().info("<ExpectedException action=add>java.net.ConnectException</ExpectedException>");
        MembershipManagerHelper.inhibitForcedDisconnectLogging(true);
        locvm.invoke(new SerializableRunnable() {

            public void run() {
                File lf = new File("");
                try {
                    Locator.startLocatorAndDS(port2, lf, properties);
                } catch (IOException ios) {
                    org.apache.geode.test.dunit.Assert.fail("Unable to start locator2", ios);
                }
            }
        });
        Object[] connectArgs = new Object[] { properties };
        SerializableRunnable crashLocator = new SerializableRunnable("Crash locator") {

            public void run() {
                Locator loc = Locator.getLocators().iterator().next();
                DistributedSystem msys = loc.getDistributedSystem();
                MembershipManagerHelper.crashDistributedSystem(msys);
                loc.stop();
            }
        };
        assertTrue(MembershipManagerHelper.getLeadMember(sys) == null);
        // properties.put("log-level", getDUnitLogLevel());
        DistributedMember mem1 = (DistributedMember) vm1.invoke(this.getClass(), "getDistributedMember", connectArgs);
        vm2.invoke(this.getClass(), "getDistributedMember", connectArgs);
        assertLeadMember(mem1, sys, 5000);
        assertEquals(sys.getDistributedMember(), MembershipManagerHelper.getCoordinator(sys));
        // crash the second vm and the locator. Should be okay
        DistributedTestUtils.crashDistributedSystem(vm2);
        locvm.invoke(crashLocator);
        assertTrue("Distributed system should not have disconnected", vm1.invoke(() -> LocatorDUnitTest.isSystemConnected()));
        // ensure quorumLost is properly invoked
        DistributionManager dm = (DistributionManager) ((InternalDistributedSystem) sys).getDistributionManager();
        MyMembershipListener listener = new MyMembershipListener();
        dm.addMembershipListener(listener);
        // ensure there is an unordered reader thread for the member
        new HighPriorityAckedMessage().send(Collections.singleton(mem1), false);
        // disconnect the first vm and demonstrate that the third vm and the
        // locator notice the failure and exit
        DistributedTestUtils.crashDistributedSystem(vm1);
        /*
       * This vm is watching vm1, which is watching vm2 which is watching locvm. It will take 3 * (3
       * * member-timeout) milliseconds to detect the full failure and eject the lost members from
       * the view.
       */
        org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("waiting for my distributed system to disconnect due to partition detection");
        Awaitility.waitAtMost(24000, TimeUnit.MILLISECONDS).pollInterval(200, TimeUnit.MILLISECONDS).until(() -> {
            return !sys.isConnected();
        });
        if (sys.isConnected()) {
            fail("Distributed system did not disconnect as expected - network partition detection is broken");
        }
        // quorumLost should be invoked if we get a ForcedDisconnect in this situation
        assertTrue("expected quorumLost to be invoked", listener.quorumLostInvoked);
        assertTrue("expected suspect processing initiated by TCPConduit", listener.suspectReasons.contains(Connection.INITIATING_SUSPECT_PROCESSING));
    } finally {
        if (locator != null) {
            locator.stop();
        }
        LogWriter bLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, System.out);
        bLogger.info("<ExpectedException action=remove>service failure</ExpectedException>");
        bLogger.info("<ExpectedException action=remove>java.net.ConnectException</ExpectedException>");
        bLogger.info("<ExpectedException action=remove>org.apache.geode.ForcedDisconnectException</ExpectedException>");
        disconnectAllFromDS();
    }
}
Also used : HighPriorityAckedMessage(org.apache.geode.distributed.internal.HighPriorityAckedMessage) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException) Properties(java.util.Properties) LocalLogWriter(org.apache.geode.internal.logging.LocalLogWriter) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) LocalLogWriter(org.apache.geode.internal.logging.LocalLogWriter) InternalLogWriter(org.apache.geode.internal.logging.InternalLogWriter) LogWriter(org.apache.geode.LogWriter) VM(org.apache.geode.test.dunit.VM) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) File(java.io.File) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest)

Example 60 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class JCALocalTransaction method begin.

@Override
public void begin() throws ResourceException {
    try {
        if (!this.initDone || this.cache.isClosed()) {
            this.init();
        }
        LogWriter logger = this.cache.getLogger();
        if (logger.fineEnabled()) {
            logger.fine("JCALocalTransaction::begin:");
        }
        TransactionManager tm = this.cache.getJTATransactionManager();
        if (this.tid != null) {
            throw new LocalTransactionException(" A transaction is already in progress");
        }
        if (tm != null && tm.getTransaction() != null) {
            if (logger.fineEnabled()) {
                logger.fine("JCAManagedConnection: JTA transaction is on");
            }
            // This is having a JTA transaction. Assuming ignore jta flag is true,
            // explicitly being a gemfire transaction.
            TXStateProxy tsp = this.gfTxMgr.getTXState();
            if (tsp == null) {
                this.gfTxMgr.begin();
                tsp = this.gfTxMgr.getTXState();
                tsp.setJCATransaction();
                this.tid = tsp.getTransactionId();
                if (logger.fineEnabled()) {
                    logger.fine("JCALocalTransaction:begun GFE transaction");
                }
            } else {
                throw new LocalTransactionException("GemFire is already associated with a transaction");
            }
        } else {
            if (logger.fineEnabled()) {
                logger.fine("JCAManagedConnection: JTA Transaction does not exist.");
            }
        }
    } catch (SystemException e) {
        throw new ResourceException(e);
    }
}
Also used : LocalTransactionException(javax.resource.spi.LocalTransactionException) SystemException(javax.transaction.SystemException) LogWriter(org.apache.geode.LogWriter) TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) TransactionManager(javax.transaction.TransactionManager) ResourceException(javax.resource.ResourceException)

Aggregations

LogWriter (org.apache.geode.LogWriter)87 Test (org.junit.Test)34 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)18 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)17 Host (org.apache.geode.test.dunit.Host)17 Region (org.apache.geode.cache.Region)15 DistributedSystem (org.apache.geode.distributed.DistributedSystem)15 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)15 VM (org.apache.geode.test.dunit.VM)13 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)12 Iterator (java.util.Iterator)11 Set (java.util.Set)11 Cache (org.apache.geode.cache.Cache)11 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)11 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)10 LocalRegion (org.apache.geode.internal.cache.LocalRegion)9 Properties (java.util.Properties)8 InternalLogWriter (org.apache.geode.internal.logging.InternalLogWriter)8 IOException (java.io.IOException)7 HashSet (java.util.HashSet)7