Skip to content

Commit

Permalink
Merge branch '3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
ctubbsii committed Jan 14, 2025
2 parents aa7b495 + d0ee570 commit 4217116
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

Expand All @@ -32,16 +32,16 @@
import org.apache.accumulo.core.data.ArrayByteSequence;
import org.apache.accumulo.core.data.Mutation;
import org.apache.accumulo.core.data.constraints.Constraint.Environment;
import org.apache.accumulo.core.security.AuthorizationContainer;
import org.apache.accumulo.core.security.ColumnVisibility;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class VisibilityConstraintTest {

VisibilityConstraint vc;
Environment env;
Mutation mutation;
private VisibilityConstraint vc;
private Environment env;
private Mutation mutation;

static final ColumnVisibility good = new ColumnVisibility("good|bad");
static final ColumnVisibility bad = new ColumnVisibility("good&bad");
Expand All @@ -57,17 +57,18 @@ public void setUp() {
vc = new VisibilityConstraint();
mutation = new Mutation("r");

ArrayByteSequence bs = new ArrayByteSequence("good".getBytes(UTF_8));

AuthorizationContainer ac = createNiceMock(AuthorizationContainer.class);
expect(ac.contains(bs)).andReturn(true);
replay(ac);

env = createMock(Environment.class);
expect(env.getAuthorizationsContainer()).andReturn(ac);
expect(env.getAuthorizationsContainer())
.andReturn(new ArrayByteSequence("good".getBytes(UTF_8))::equals).anyTimes();

replay(env);
}

@AfterEach
public void tearDown() {
verify(env);
}

@Test
public void testNoVisibility() {
mutation.put(D, D, D);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ private static void testMerge(List<TabletMetadata> inputTablets, TableId tableId
EasyMock.expectLastCall().once();

// setup processing of conditional mutations
Ample.ConditionalResult cr = EasyMock.niceMock(Ample.ConditionalResult.class);
Ample.ConditionalResult cr = EasyMock.createMock(Ample.ConditionalResult.class);
EasyMock.expect(cr.getStatus()).andReturn(Ample.ConditionalResult.Status.ACCEPTED)
.atLeastOnce();
EasyMock.expect(tabletsMutator.process()).andReturn(Map.of(lastExtent, cr)).atLeastOnce();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ public void testManyColumns() throws Exception {
EasyMock.expect(tabletsMutator.mutateTablet(origExtent)).andReturn(tablet3Mutator);

// setup processing of conditional mutations
Ample.ConditionalResult cr = EasyMock.niceMock(Ample.ConditionalResult.class);
Ample.ConditionalResult cr = EasyMock.createMock(Ample.ConditionalResult.class);
EasyMock.expect(cr.getExtent()).andReturn(origExtent).atLeastOnce();
EasyMock.expect(cr.getStatus()).andReturn(Ample.ConditionalResult.Status.ACCEPTED)
.atLeastOnce();
EasyMock.expect(tabletsMutator.process())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,9 @@ public class ActiveAssignmentRunnable implements Runnable {

public ActiveAssignmentRunnable(ConcurrentHashMap<KeyExtent,RunnableStartedAt> activeAssignments,
KeyExtent extent, Runnable delegate) {
requireNonNull(activeAssignments);
requireNonNull(extent);
requireNonNull(delegate);
this.activeAssignments = activeAssignments;
this.extent = extent;
this.delegate = delegate;
this.activeAssignments = requireNonNull(activeAssignments);
this.extent = requireNonNull(extent);
this.delegate = requireNonNull(delegate);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,8 @@ public TabletServerResourceManager(ServerContext context, TabletHostingServer ts

// We can use the same map for both metadata and normal assignments since the keyspace (extent)
// is guaranteed to be unique. Schedule the task once, the task will reschedule itself.
ThreadPools.watchCriticalScheduledTask(context.getScheduledExecutor().schedule(
new AssignmentWatcher(acuConf, context, activeAssignments), 5000, TimeUnit.MILLISECONDS));
ThreadPools.watchCriticalScheduledTask(context.getScheduledExecutor()
.schedule(new AssignmentWatcher(context, activeAssignments), 5000, TimeUnit.MILLISECONDS));
}

public int getOpenFiles() {
Expand All @@ -436,24 +436,22 @@ public static class AssignmentWatcher implements Runnable {
private static long longAssignments = 0;

private final Map<KeyExtent,RunnableStartedAt> activeAssignments;
private final AccumuloConfiguration conf;
private final ServerContext context;

public static long getLongAssignments() {
return longAssignments;
}

public AssignmentWatcher(AccumuloConfiguration conf, ServerContext context,
public AssignmentWatcher(ServerContext context,
Map<KeyExtent,RunnableStartedAt> activeAssignments) {
this.conf = conf;
this.context = context;
this.activeAssignments = activeAssignments;
}

@Override
public void run() {
final long millisBeforeWarning =
this.conf.getTimeInMillis(Property.TSERV_ASSIGNMENT_DURATION_WARNING);
context.getConfiguration().getTimeInMillis(Property.TSERV_ASSIGNMENT_DURATION_WARNING);
try {
long now = System.currentTimeMillis();
KeyExtent extent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,43 @@
*/
package org.apache.accumulo.tserver;

import java.util.HashMap;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;

import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledThreadPoolExecutor;

import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.ConfigurationCopy;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.data.TableId;
import org.apache.accumulo.core.dataImpl.KeyExtent;
import org.apache.accumulo.server.ServerContext;
import org.apache.accumulo.tserver.TabletServerResourceManager.AssignmentWatcher;
import org.easymock.EasyMock;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class AssignmentWatcherTest {

private Map<KeyExtent,RunnableStartedAt> assignments;
private ServerContext context;
private AccumuloConfiguration conf;
private AssignmentWatcher watcher;

@BeforeEach
public void setup() {
assignments = new HashMap<>();
context = EasyMock.createMock(ServerContext.class);
conf = EasyMock.createNiceMock(AccumuloConfiguration.class);
watcher = new AssignmentWatcher(conf, context, assignments);
}

@Test
public void testAssignmentWarning() {
ActiveAssignmentRunnable task = EasyMock.createMock(ActiveAssignmentRunnable.class);
RunnableStartedAt run = new RunnableStartedAt(task, System.currentTimeMillis());
EasyMock.expect(context.getConfiguration()).andReturn(conf).anyTimes();
EasyMock.expect(conf.getCount(EasyMock.isA(Property.class))).andReturn(1).anyTimes();
EasyMock.expect(conf.getTimeInMillis(EasyMock.isA(Property.class))).andReturn(0L).anyTimes();
EasyMock.expect(context.getScheduledExecutor())
.andReturn((ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(1)).anyTimes();
assignments.put(new KeyExtent(TableId.of("1"), null, null), run);
var e = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(1);
var c = new ConfigurationCopy(Map.of(Property.TSERV_ASSIGNMENT_DURATION_WARNING.getKey(), "0"));
ServerContext context = createMock(ServerContext.class);
expect(context.getScheduledExecutor()).andReturn(e);
expect(context.getConfiguration()).andReturn(c);

ActiveAssignmentRunnable task = createMock(ActiveAssignmentRunnable.class);
expect(task.getException()).andReturn(new Exception("Assignment warning happened"));

var assignments = Map.of(new KeyExtent(TableId.of("1"), null, null),
new RunnableStartedAt(task, System.currentTimeMillis()));
var watcher = new AssignmentWatcher(context, assignments);

EasyMock.expect(task.getException()).andReturn(new Exception("Assignment warning happened"));
EasyMock.replay(context, task);
replay(context, task);
watcher.run();
EasyMock.verify(context, task);
verify(context, task);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.replay;
Expand Down Expand Up @@ -85,12 +84,17 @@ public void set(String in) {
}

@BeforeEach
public void setUp() throws IOException {
public void setUp() throws Exception {
input = new SettableInputStream();
baos = new ByteArrayOutputStream();

writer = createNiceMock(BatchWriter.class);
shellState = createNiceMock(Shell.class);
writer = createMock(BatchWriter.class);
writer.addMutation(anyObject());
expectLastCall().anyTimes();
writer.close();
expectLastCall().anyTimes();

shellState = createMock(Shell.class);

terminal = new DumbTerminal(input, baos);
terminal.setSize(new Size(80, 24));
Expand Down Expand Up @@ -197,7 +201,7 @@ public void testYes() throws IOException {
@Test
public void testMutationException() throws MutationsRejectedException {
MutationsRejectedException mre = createMock(MutationsRejectedException.class);
BatchWriter exceptionWriter = createNiceMock(BatchWriter.class);
BatchWriter exceptionWriter = createMock(BatchWriter.class);
exceptionWriter.close();
expectLastCall().andThrow(mre);
exceptionWriter.addMutation(anyObject(Mutation.class));
Expand Down

0 comments on commit 4217116

Please sign in to comment.