sapling/eden/fs/testharness/TestDispatcher.h
Xavier Deguillard 62076b545e inodes: move dispatchers around
Summary:
Instead of having one "Dispatcher" type that the various backend overload,
let's simply have a per-mount type dispatcher type. The previous model worked
fine when EdenFS supported only one way of mounting a repository, but with NFS
coming, unix platform will support both FUSE and NFS, making the Dispatcher
overload nonsensical.

As a behavioral change, the dispatcher lifetime and ownership is changed a bit.
It used to live for the duration of the EdenMount object, but is now tied to
the channel lifetime, as it is now owned by it.

Reviewed By: kmancini

Differential Revision: D26329477

fbshipit-source-id: 3959b90a4909e3ab0898caa308f54686f59a943c
2021-02-10 11:52:06 -08:00

71 lines
1.7 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#pragma once
#include <folly/Synchronized.h>
#include <folly/futures/Future.h>
#include <folly/futures/Promise.h>
#include <chrono>
#include <condition_variable>
#include <unordered_map>
#include "eden/fs/fuse/FuseDispatcher.h"
#include "eden/fs/store/ObjectStore.h"
#include "eden/fs/utils/PathFuncs.h"
namespace facebook::eden {
/**
* A FUSE Dispatcher implementation for use in unit tests.
*
* It allows the test code to generate responses to specific requests on
* demand.
*/
class TestDispatcher : public FuseDispatcher {
public:
/**
* Data for a pending FUSE_LOOKUP request.
*/
struct PendingLookup {
PendingLookup(InodeNumber parent, PathComponentPiece name)
: parent(parent), name(name.copy()) {}
InodeNumber parent;
PathComponent name;
folly::Promise<fuse_entry_out> promise;
};
using FuseDispatcher::FuseDispatcher;
folly::Future<fuse_entry_out> lookup(
uint64_t requestID,
InodeNumber parent,
PathComponentPiece name,
ObjectFetchContext& context) override;
/**
* Wait for the dispatcher to receive a FUSE_LOOKUP request with the
* specified request ID.
*
* Returns a PendingLookup object that can be used to respond to the request.
*/
PendingLookup waitForLookup(
uint64_t requestId,
std::chrono::milliseconds timeout = std::chrono::milliseconds(500));
private:
struct State {
std::unordered_map<uint64_t, PendingLookup> pendingLookups;
};
folly::Synchronized<State, std::mutex> state_;
std::condition_variable requestReceived_;
};
} // namespace facebook::eden