Search in sources :

Example 81 with LogWriter

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

the class TestFunction method execute5.

public void execute5(FunctionContext context) {
    DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
    LogWriter logger = ds.getLogWriter();
    if (this.props.get("TERMINATE") != null && this.props.get("TERMINATE").equals("YES")) {
        logger.info("Function Terminated");
    } else {
        try {
            synchronized (this) {
                logger.info("Function Running");
                this.wait(20000);
            }
        } catch (InterruptedException e) {
        }
    }
    context.getResultSender().lastResult(Boolean.TRUE);
}
Also used : LogWriter(org.apache.geode.LogWriter) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 82 with LogWriter

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

the class CustomConfigWithCacheIntegrationTest method cacheLogWriterMessageShouldMatchCustomConfig.

@Test
public void cacheLogWriterMessageShouldMatchCustomConfig() throws Exception {
    String logLogger = LogService.MAIN_LOGGER_NAME;
    Level logLevel = Level.INFO;
    String logMessage = "this is a log statement from " + testName.getMethodName();
    LogWriter logger = this.cache.getLogger();
    assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isFalse();
    BasicAppender.clearEvents();
    logger.info(logMessage);
    BasicAppender appender = BasicAppender.getInstance();
    assertThat(appender).isNotNull();
    assertThat(appender.events().size()).isGreaterThan(0);
    LogEvent event = null;
    for (LogEvent logEvent : appender.events()) {
        if (logEvent.getMessage().getFormattedMessage().contains(logMessage)) {
            event = logEvent;
            break;
        }
    }
    assertThat(event).isNotNull();
    assertThat(event.getLoggerName()).isEqualTo(logLogger);
    assertThat(event.getLevel()).isEqualTo(logLevel);
    assertThat(event.getMessage().getFormattedMessage()).isEqualTo(logMessage);
    assertThat(systemOutRule.getLog()).contains(logLevel.name());
    assertThat(systemOutRule.getLog()).contains(logMessage);
    assertThat(systemOutRule.getLog()).contains(CONFIG_LAYOUT_PREFIX);
    assertThat(systemOutRule.getLog()).containsPattern(defineLogStatementRegex(logLevel, logMessage));
}
Also used : LogWriter(org.apache.geode.LogWriter) LogEvent(org.apache.logging.log4j.core.LogEvent) Level(org.apache.logging.log4j.Level) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 83 with LogWriter

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

the class InterestResultPolicyDUnitTest method testBug35358.

/**
   * This test does the following<br>
   * 1)Create client cache and region<br>
   * 2)Call registerInterest with specific keys (having extra keys other than those pre-populated on
   * server cache) and policy:KEYS<br>
   * 3)At the end of registerInterest call, verify that only prepolulated entries are created in the
   * client cache with null values (entries for keys in the keylist which are not on the server
   * should not be created on the client as a result of registerInterest call)<br>
   */
@Test
public void testBug35358() {
    Host host = Host.getHost(0);
    LogWriter logger = getSystem().getLogWriter();
    logger.fine("testBug35358 BEGIN");
    Object[] objArr = new Object[2];
    objArr[0] = InterestResultPolicy.KEYS;
    /* registering for 5 extra keys */
    objArr[1] = new Integer(PREPOPULATED_ENTRIES + 5);
    vm1.invoke(() -> InterestResultPolicyDUnitTest.createClientCache(NetworkUtils.getServerHostName(host), new Integer(PORT)));
    vm1.invoke(InterestResultPolicyDUnitTest.class, "registerInterest", objArr);
    vm1.invoke(InterestResultPolicyDUnitTest.class, "verifyResult", objArr);
    Integer cnt = (Integer) vm0.invoke(() -> InterestResultPolicyDUnitTest.getEntryCount());
    assertEquals(cnt.intValue(), PREPOPULATED_ENTRIES);
    logger.fine("testBug35358 END");
}
Also used : LogWriter(org.apache.geode.LogWriter) Host(org.apache.geode.test.dunit.Host) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 84 with LogWriter

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

the class InterestResultPolicyDUnitTest method testPolicyKeysValues.

/**
   * This test does the following<br>
   * 1)Create client cache and region<br>
   * 2)Call registerInterest with all keys pre-populated on server and policy:KEYS_VALUES<br>
   * 3)At the end of registerInterest call, verify that all entries are created in the client cache
   * with values<br>
   */
@Test
public void testPolicyKeysValues() {
    LogWriter logger = getSystem().getLogWriter();
    logger.fine("testPolicyKeyValues BEGIN");
    Object[] objArr = new Object[2];
    objArr[0] = InterestResultPolicy.KEYS_VALUES;
    objArr[1] = new Integer(PREPOPULATED_ENTRIES);
    Host host = Host.getHost(0);
    vm1.invoke(() -> InterestResultPolicyDUnitTest.createClientCache(NetworkUtils.getServerHostName(host), new Integer(PORT)));
    vm1.invoke(InterestResultPolicyDUnitTest.class, "registerInterest", objArr);
    vm1.invoke(InterestResultPolicyDUnitTest.class, "verifyResult", objArr);
    logger.fine("testPolicyKeyValues END");
}
Also used : LogWriter(org.apache.geode.LogWriter) Host(org.apache.geode.test.dunit.Host) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 85 with LogWriter

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

the class InterestResultPolicyDUnitTest method testPolicyNone.

/**
   * This test does the following<br>
   * 1)Create client cache and region<br>
   * 2)Call registerInterest with all keys pre-populated on server and policy:NONE<br>
   * 3)At the end of registerInterest call, verify that no entries are created in the client
   * cache<br>
   */
@Test
public void testPolicyNone() {
    LogWriter logger = getSystem().getLogWriter();
    logger.fine("testPolicyNone BEGIN");
    Object[] objArr = new Object[2];
    objArr[0] = InterestResultPolicy.NONE;
    objArr[1] = new Integer(PREPOPULATED_ENTRIES);
    Host host = Host.getHost(0);
    vm1.invoke(() -> InterestResultPolicyDUnitTest.createClientCache(NetworkUtils.getServerHostName(host), new Integer(PORT)));
    vm1.invoke(InterestResultPolicyDUnitTest.class, "registerInterest", objArr);
    vm1.invoke(InterestResultPolicyDUnitTest.class, "verifyResult", objArr);
    logger.fine("testPolicyNone END");
}
Also used : LogWriter(org.apache.geode.LogWriter) Host(org.apache.geode.test.dunit.Host) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

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