use of com.google.common.base.Charsets.UTF_8 in project buck by facebook.
the class ParserTest method resolveTargetSpecsPreservesOrder.
@Test
public void resolveTargetSpecsPreservesOrder() throws Exception {
BuildTarget foo = BuildTargetFactory.newInstance(filesystem, "//foo:foo");
Path buckFile = cellRoot.resolve("foo/BUCK");
Files.createDirectories(buckFile.getParent());
Files.write(buckFile, "genrule(name='foo', out='foo', cmd='foo')".getBytes(UTF_8));
BuildTarget bar = BuildTargetFactory.newInstance(filesystem, "//bar:bar");
buckFile = cellRoot.resolve("bar/BUCK");
Files.createDirectories(buckFile.getParent());
Files.write(buckFile, "genrule(name='bar', out='bar', cmd='bar')".getBytes(UTF_8));
ImmutableList<ImmutableSet<BuildTarget>> targets = parser.resolveTargetSpecs(eventBus, cell, false, executorService, ImmutableList.of(TargetNodePredicateSpec.of(x -> true, BuildFileSpec.fromRecursivePath(Paths.get("bar"), cell.getRoot())), TargetNodePredicateSpec.of(x -> true, BuildFileSpec.fromRecursivePath(Paths.get("foo"), cell.getRoot()))), SpeculativeParsing.of(true), ParserConfig.ApplyDefaultFlavorsMode.ENABLED);
assertThat(targets, equalTo(ImmutableList.of(ImmutableSet.of(bar), ImmutableSet.of(foo))));
targets = parser.resolveTargetSpecs(eventBus, cell, false, executorService, ImmutableList.of(TargetNodePredicateSpec.of(x -> true, BuildFileSpec.fromRecursivePath(Paths.get("foo"), cell.getRoot())), TargetNodePredicateSpec.of(x -> true, BuildFileSpec.fromRecursivePath(Paths.get("bar"), cell.getRoot()))), SpeculativeParsing.of(true), ParserConfig.ApplyDefaultFlavorsMode.ENABLED);
assertThat(targets, equalTo(ImmutableList.of(ImmutableSet.of(foo), ImmutableSet.of(bar))));
}
use of com.google.common.base.Charsets.UTF_8 in project nakadi by zalando.
the class AbstractZkSubscriptionClient method commitOffsets.
@Override
public List<Boolean> commitOffsets(final List<SubscriptionCursorWithoutToken> cursors, final Comparator<SubscriptionCursorWithoutToken> comparator) {
final Map<EventTypePartition, List<SubscriptionCursorWithoutToken>> grouped = cursors.stream().collect(Collectors.groupingBy(SubscriptionCursorWithoutToken::getEventTypePartition));
try {
final Map<EventTypePartition, Iterator<Boolean>> committedOverall = new HashMap<>();
for (final Map.Entry<EventTypePartition, List<SubscriptionCursorWithoutToken>> entry : grouped.entrySet()) {
final String offsetPath = getOffsetPath(entry.getKey());
final List<Boolean> committed;
committed = executeWithRetry(() -> {
final Stat stat = new Stat();
final byte[] currentOffsetData = getCurator().getData().storingStatIn(stat).forPath(offsetPath);
final String currentMaxOffset = new String(currentOffsetData, UTF_8);
SubscriptionCursorWithoutToken currentMaxCursor = new SubscriptionCursorWithoutToken(entry.getKey().getEventType(), entry.getKey().getPartition(), currentMaxOffset);
final List<Boolean> commits = Lists.newArrayList();
for (final SubscriptionCursorWithoutToken cursor : entry.getValue()) {
if (comparator.compare(cursor, currentMaxCursor) > 0) {
currentMaxCursor = cursor;
commits.add(true);
} else {
commits.add(false);
}
}
if (!currentMaxCursor.getOffset().equals(currentMaxOffset)) {
getLog().info("Committing {} to {}", currentMaxCursor.getOffset(), offsetPath);
getCurator().setData().withVersion(stat.getVersion()).forPath(offsetPath, currentMaxCursor.getOffset().getBytes(Charsets.UTF_8));
}
return commits;
}, new RetryForSpecifiedCountStrategy<List<Boolean>>(COMMIT_CONFLICT_RETRY_TIMES).withExceptionsThatForceRetry(KeeperException.BadVersionException.class));
committedOverall.put(entry.getKey(), Optional.ofNullable(committed).orElse(Collections.nCopies(entry.getValue().size(), false)).iterator());
}
return cursors.stream().map(cursor -> committedOverall.get(cursor.getEventTypePartition()).next()).collect(Collectors.toList());
} catch (final Exception ex) {
throw new NakadiRuntimeException(ex);
}
}
use of com.google.common.base.Charsets.UTF_8 in project bookkeeper by apache.
the class BookieShellTest method setup.
@Before
public void setup() throws Exception {
// setup the required mocks before constructing bookie shell.
this.mockLastMarkCommand = mock(LastMarkCommand.class);
whenNew(LastMarkCommand.class).withNoArguments().thenReturn(mockLastMarkCommand);
this.mockSimpleTestCommand = spy(new SimpleTestCommand());
doNothing().when(mockSimpleTestCommand).run(any(ServerConfiguration.class));
whenNew(SimpleTestCommand.class).withNoArguments().thenReturn(mockSimpleTestCommand);
this.mockListBookiesCommand = spy(new ListBookiesCommand());
doNothing().when(mockListBookiesCommand).run(any(ServerConfiguration.class));
whenNew(ListBookiesCommand.class).withNoArguments().thenReturn(mockListBookiesCommand);
// construct the bookie shell.
this.shell = new BookieShell(LedgerIdFormatter.LONG_LEDGERID_FORMATTER, EntryFormatter.STRING_FORMATTER);
this.admin = PowerMockito.mock(BookKeeperAdmin.class);
whenNew(BookKeeperAdmin.class).withParameterTypes(ClientConfiguration.class).withArguments(any(ClientConfiguration.class)).thenReturn(admin);
this.clientConf = new ClientConfiguration();
this.clientConf.setMetadataServiceUri("zk://127.0.0.1/path/to/ledgers");
when(admin.getConf()).thenReturn(this.clientConf);
this.rm = PowerMockito.mock(RegistrationManager.class);
this.cookie = Cookie.newBuilder().setBookieHost("127.0.0.1:3181").setInstanceId("xyz").setJournalDirs("/path/to/journal/dir").setLedgerDirs("/path/to/journal/dir").setLayoutVersion(Cookie.CURRENT_COOKIE_LAYOUT_VERSION).build();
this.version = new LongVersion(1L);
when(rm.readCookie(anyString())).thenReturn(new Versioned<>(cookie.toString().getBytes(UTF_8), version));
this.driver = mock(MetadataBookieDriver.class);
when(driver.getRegistrationManager()).thenReturn(rm);
PowerMockito.mockStatic(MetadataDrivers.class);
PowerMockito.doAnswer(invocationOnMock -> {
Function<RegistrationManager, Object> function = invocationOnMock.getArgument(1);
function.apply(rm);
return null;
}).when(MetadataDrivers.class, "runFunctionWithRegistrationManager", any(ServerConfiguration.class), any(Function.class));
}
use of com.google.common.base.Charsets.UTF_8 in project nakadi by zalando.
the class NewZkSubscriptionClient method createTopologyAndOffsets.
@Override
protected byte[] createTopologyAndOffsets(final Collection<SubscriptionCursorWithoutToken> cursors) throws Exception {
for (final SubscriptionCursorWithoutToken cursor : cursors) {
getCurator().create().creatingParentsIfNeeded().forPath(getOffsetPath(cursor.getEventTypePartition()), cursor.getOffset().getBytes(UTF_8));
}
final Partition[] partitions = cursors.stream().map(cursor -> new Partition(cursor.getEventType(), cursor.getPartition(), null, null, Partition.State.UNASSIGNED)).toArray(Partition[]::new);
final Topology topology = new Topology(partitions, "", 0);
getLog().info("Generating topology {}", topology);
return objectMapper.writeValueAsBytes(topology);
}
Aggregations