Search in sources :

Example 51 with LogWriter

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

the class CreateAlterDestroyRegionCommands method findMembersForRegion.

private Set<DistributedMember> findMembersForRegion(InternalCache cache, ManagementService managementService, String regionPath) {
    Set<DistributedMember> membersList = new HashSet<>();
    Set<String> regionMemberIds = new HashSet<>();
    MBeanServer mbeanServer = MBeanJMXAdapter.mbeanServer;
    // needs to be escaped with quotes if it contains a hyphen
    if (regionPath.contains("-")) {
        regionPath = "\"" + regionPath + "\"";
    }
    String queryExp = MessageFormat.format(MBeanJMXAdapter.OBJECTNAME__REGION_MXBEAN, regionPath, "*");
    try {
        ObjectName queryExpON = new ObjectName(queryExp);
        Set<ObjectName> queryNames = mbeanServer.queryNames(null, queryExpON);
        if (queryNames == null || queryNames.isEmpty()) {
            // protects against null pointer exception below
            return membersList;
        }
        boolean addedOneRemote = false;
        for (ObjectName regionMBeanObjectName : queryNames) {
            try {
                RegionMXBean regionMXBean = managementService.getMBeanInstance(regionMBeanObjectName, RegionMXBean.class);
                if (regionMXBean != null) {
                    RegionAttributesData regionAttributes = regionMXBean.listRegionAttributes();
                    String scope = regionAttributes.getScope();
                    // propagated.
                    if (Scope.LOCAL.equals(Scope.fromString(scope))) {
                        regionMemberIds.add(regionMXBean.getMember());
                    } else {
                        if (!addedOneRemote) {
                            regionMemberIds.add(regionMXBean.getMember());
                            addedOneRemote = true;
                        }
                    }
                }
            } catch (ClassCastException e) {
                LogWriter logger = cache.getLogger();
                if (logger.finerEnabled()) {
                    logger.finer(regionMBeanObjectName + " is not a " + RegionMXBean.class.getSimpleName(), e);
                }
            }
        }
        if (!regionMemberIds.isEmpty()) {
            membersList = getMembersByIds(cache, regionMemberIds);
        }
    } catch (MalformedObjectNameException | NullPointerException e) {
        LogWrapper.getInstance().info(e.getMessage(), e);
    }
    return membersList;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) DistributedRegionMXBean(org.apache.geode.management.DistributedRegionMXBean) RegionMXBean(org.apache.geode.management.RegionMXBean) RegionAttributesData(org.apache.geode.management.RegionAttributesData) ObjectName(javax.management.ObjectName) LogWriter(org.apache.geode.LogWriter) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) HashSet(java.util.HashSet) MBeanServer(javax.management.MBeanServer)

Example 52 with LogWriter

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

the class CompiledJunctionInternalsJUnitTest method testOrganizedOperandsOfSingleRangeJunctionWithNoIterOperandForAND_1.

//////////////////////////////////////////////////////////////////////////////
/// ***************************BEGIN*********************************************//
// Tests the RangeJunction's organizeOperands for the correct creation of Evaluator.
// These tests are dependent on whether the RangeJunction is of type AND or OR
// All the tests below are for AND
/**
   * Tests the functionality of organizedOperands function of a RangeJunction which is an AND with
   * no IterOperand. If the RangeJunction boils down to a single condition which can be evalauted as
   * a CompiledComparison then the filter operand will be a CompiledComparison
   * 
   */
@Test
public void testOrganizedOperandsOfSingleRangeJunctionWithNoIterOperandForAND_1() {
    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 CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(2)), OQLLexerTokenTypes.TOK_LT);
        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 53 with LogWriter

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

the class CompiledJunctionInternalsJUnitTest method testNotEqualCoupledWithUndefinedAndNotNull.

/**
   * If possible , in case where RangeJunction contains something like a != 7 and a != undefined & a
   * != null, since undefined & null are not groupable , the a != 7 is also evaluated individually.
   * In such case, it makes sense not to create an Object of
   * rangeJunction.NotEqualConditionEvaluator for evaluating a !=7 , which however is the case now.
   * May be at some point, we should either try to club null & undefined as a part of
   * RangeJunctionEvaluator or we should not create an object of NotEqualConditionEvaluator.
   * 
   */
@Ignore
@Test
public void testNotEqualCoupledWithUndefinedAndNotNull() {
    LogWriter logger = CacheUtils.getLogger();
    try {
        ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache());
        this.bindIteratorsAndCreateIndex(context);
        // Case 2 : a != 7 and a != null and a != undefined
        CompiledValue[] cv1 = new CompiledValue[3];
        cv1[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_NE);
        cv1[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(null), OQLLexerTokenTypes.TOK_NE);
        cv1[2] = new CompiledUndefined(new CompiledPath(new CompiledID("p"), "ID"), false);
        OrganizedOperands oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv1, context);
        assertTrue("Filter Openad of OrganizedOperand is not of type RangeJunction", oo.filterOperand instanceof RangeJunction);
        RangeJunction rj = (RangeJunction) oo.filterOperand;
        OrganizedOperands oo1 = rj.organizeOperands(context);
        assertTrue(oo1.filterOperand instanceof GroupJunction);
        CompiledValue[] ops = ((GroupJunction) oo1.filterOperand)._operands;
        assertTrue(cv1[0] == ops[0] || cv1[0] == ops[1] || cv1[0] == ops[2]);
        assertTrue(cv1[1] == ops[0] || cv1[1] == ops[1] || cv1[1] == ops[2]);
        assertTrue(cv1[2] == ops[0] || cv1[2] == ops[1] || cv1[2] == ops[2]);
    } catch (Exception e) {
        logger.error(e.toString());
        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 54 with LogWriter

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

the class CompiledJunctionInternalsJUnitTest method testOrganizedOperandsOfSingleRangeJunctionWithTwoIterOperandsForAND_4.

/**
   * Tests the functionality of organizedOperands function of a RangeJunction which is an AND with
   * two IterOperands but where the operator needs reflection. as the condition is Key <= Path (
   * which means Path less than Key) The RangeJunction boils down to a condition and a NOT EQUAL
   * which will be evalauted as a SingleCondnEvaluator so the filter operand will be a
   * SingleCondnEvaluator. Its Iter operand will be a CompiledJunction. This checks for the
   * SingleCondnEvaluator with > operator
   * 
   */
@Test
public void testOrganizedOperandsOfSingleRangeJunctionWithTwoIterOperandsForAND_4() {
    LogWriter logger = CacheUtils.getCache().getLogger();
    try {
        CompiledComparison[] cv = null;
        ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache());
        this.bindIteratorsAndCreateIndex(context);
        cv = new CompiledComparison[7];
        cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GT);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(5)), OQLLexerTokenTypes.TOK_GT);
        cv[2] = new CompiledComparison(new CompiledLiteral(new Integer(2)), new CompiledPath(new CompiledID("p"), "ID"), OQLLexerTokenTypes.TOK_LT);
        cv[3] = new CompiledComparison(new CompiledLiteral(new Integer(2)), new CompiledPath(new CompiledID("p"), "createTime"), OQLLexerTokenTypes.TOK_GT);
        cv[4] = new CompiledComparison(new CompiledLiteral(new String("xyz")), new CompiledPath(new CompiledID("p"), "getPk"), OQLLexerTokenTypes.TOK_GT);
        cv[5] = new CompiledComparison(new CompiledLiteral(new Integer(100)), new CompiledPath(new CompiledID("p"), "ID"), OQLLexerTokenTypes.TOK_NE);
        cv[6] = new CompiledComparison(new CompiledLiteral(new Integer(200)), new CompiledPath(new CompiledID("p"), "ID"), OQLLexerTokenTypes.TOK_NE);
        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);
        assertTrue(oo1.iterateOperand instanceof CompiledJunction);
        assertTrue(oo1.iterateOperand.getChildren().size() == 2);
        assertTrue(oo1.iterateOperand.getChildren().get(0) == cv[3]);
        assertTrue(oo1.iterateOperand.getChildren().get(1) == cv[4]);
        assertTrue(RangeJunction.isInstanceOfSingleCondnEvaluator(oo1.filterOperand));
        Set keysToRemove = RangeJunction.getKeysToBeRemoved(oo1.filterOperand);
        assertEquals(2, keysToRemove.size());
        assertTrue(keysToRemove.contains(new Integer(100)));
        assertTrue(keysToRemove.contains(new Integer(200)));
    } catch (Exception e) {
        logger.error(e);
        fail(e.toString());
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) LogWriter(org.apache.geode.LogWriter) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 55 with LogWriter

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

the class CompiledJunctionInternalsJUnitTest method testOrganizedOperandsOfSingleRangeJunctionWithIterOperandForAND_1.

/**
   * Tests the functionality of organizedOperands function of a RangeJunction which is an AND with a
   * IterOperand but where the operator needs reflection. as the condition is Key > Path ( which
   * means Path less than Key) The RangeJunction boils down to a single condition which can be
   * evalauted as a CompiledComparison so the filter operand will be a CompiledComparison. Thus the
   * organizdeOperand's filter operand will be a CompiledComparison while its Iteroperand will be a
   * CompiledComparison
   * 
   */
@Test
public void testOrganizedOperandsOfSingleRangeJunctionWithIterOperandForAND_1() {
    LogWriter logger = CacheUtils.getCache().getLogger();
    try {
        CompiledComparison[] cv = null;
        ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache());
        this.bindIteratorsAndCreateIndex(context);
        cv = new CompiledComparison[4];
        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);
        cv[3] = new CompiledComparison(new CompiledLiteral(new Integer(2)), new CompiledPath(new CompiledID("p"), "createTime"), 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);
        assertEquals(cv[3], oo1.iterateOperand);
        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)

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