wy96f commented on a change in pull request #2547: Patched with live lock evaluation URL: https://github.com/apache/activemq-artemis/pull/2547#discussion_r319480117
########## File path: tests/extra-tests/src/test/java/org/apache/activemq/artemis/tests/extras/byteman/FileLockMonitorTest.java ########## @@ -0,0 +1,131 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.tests.extras.byteman; + +import java.io.File; +import java.io.IOException; +import java.util.concurrent.ScheduledThreadPoolExecutor; + +import org.apache.activemq.artemis.core.server.ActivateCallback; +import org.apache.activemq.artemis.core.server.impl.FileLockNodeManager; +import org.apache.activemq.artemis.core.server.impl.FileLockNodeManager.LockListener; +import org.jboss.byteman.contrib.bmunit.BMRule; +import org.jboss.byteman.contrib.bmunit.BMRules; +import org.jboss.byteman.contrib.bmunit.BMUnitRunner; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(BMUnitRunner.class) +public class FileLockMonitorTest { + + private File sharedDir; + private volatile boolean lostLock = false; + private volatile FileLockNodeManager nodeManager; + private ScheduledThreadPoolExecutor executor; + + @Before + public void handleLockFile() throws IOException { + sharedDir = File.createTempFile("shared-dir", ""); + sharedDir.delete(); + Assert.assertTrue(sharedDir.mkdir()); + lostLock = false; + } + + @Test + @BMRules(rules = { + @BMRule(name = "lock is invalid", targetClass = "sun.nio.ch.FileLockImpl", targetMethod = "isValid", action = "return false;") }) + public void testLockMonitorInvalid() throws Exception { + lostLock = false; + startServer(); + Thread.sleep(5000); + if (!lostLock) { + throw new Exception("The FileLockNodeManager should have lost the lock"); + } + nodeManager.isStarted(); + nodeManager.crashLiveServer(); + executor.shutdown(); + } + + @Test + @BMRules(rules = { + @BMRule(name = "lock is invalid", targetClass = "org.apache.activemq.artemis.core.server.impl.FileLockNodeManager", targetMethod = "getState", action = "throw new java.io.IOException(\"EFS is disconnected\");") }) + public void testLockMonitorIOException() throws Exception { + lostLock = false; + startServer(); + Thread.sleep(5000); Review comment: use a latch, a wait, etc. instead of sleep. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
